Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
680
How do I sort groups at runtime that have containers ?
posted

The below code (an example app) sorts groups that have been loaded dynamically BUT, I lose the user controls loaded into the group containers.

Can anyone tell me what I need to do to get this to work:

public Form1()

{

InitializeComponent();

ultraExplorerBar1.ViewStyle =
UltraExplorerBarViewStyle.Office2003;
ultraExplorerBar1.Style = UltraExplorerBarStyle.OutlookNavigationPane;

}

private void btnLoad_Click(object sender, EventArgs e)

{

ultraExplorerBar1.BeginUpdate();

ultraExplorerBar1.Groups.Clear();

AddControl(
new UserControl1("User Control 1"), "My User Control 1");AddControl(new UserControl1("User Control 2"), "My User Control 2");

ultraExplorerBar1.EndUpdate();

}

private void AddControl(Control c, string text)

{

UltraExplorerBarGroup newGroup = ultraExplorerBar1.Groups.Add(text);

newGroup.Text = text;

newGroup.Settings.Style =
GroupStyle.ControlContainer;c.Dock = DockStyle.Fill;

c.Parent = newGroup.Container;

}

private void btnReorder_Click(object sender, EventArgs e)

{

ultraExplorerBar1.BeginUpdate();

UltraExplorerBarGroup[ temp = new UltraExplorerBarGroup[ultraExplorerBar1.Groups.Count];

// copy groups into array and remove from explorer bar

for (int x = temp.Length - 1; x >= 0; x--)

{

temp[x] = ultraExplorerBar1.Groups[x];

ultraExplorerBar1.Groups.RemoveAt(x);

}

// reverse array

Array.Reverse(temp);

// add groups back

for (int x = 0; x < temp.Length; x++)

{

ultraExplorerBar1.Groups.Add(temp[x]);

}

ultraExplorerBar1.EndUpdate();

}

Parents
  • 69832
    Offline posted

    When a group is removed from the Groups collection, its container control is disposed of, because if we didn't do that it would cause a memory leak. You should report the fact that there is no publicly exposed Sort method off the Groups collection as a bug; I think that would be the best solution to this problem.

    In the meantime, I think you can work around this by pulling the UserControl(s) out of the container's Controls collection, stashing them somewhere before you clear the Groups collection, and then re-adding them to the new containers after you add the groups back in.

Reply Children
No Data