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:
{
InitializeComponent();ultraExplorerBar1.ViewStyle = UltraExplorerBarViewStyle.Office2003;ultraExplorerBar1.Style = UltraExplorerBarStyle.OutlookNavigationPane;
InitializeComponent();
}
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();
ultraExplorerBar1.BeginUpdate();
ultraExplorerBar1.Groups.Clear();
ultraExplorerBar1.EndUpdate();
UltraExplorerBarGroup newGroup = ultraExplorerBar1.Groups.Add(text); newGroup.Text = text;newGroup.Settings.Style = GroupStyle.ControlContainer;c.Dock = DockStyle.Fill; c.Parent = newGroup.Container;
newGroup.Text = text;
c.Parent = newGroup.Container;
ultraExplorerBar1.BeginUpdate();UltraExplorerBarGroup[ temp = new UltraExplorerBarGroup[ultraExplorerBar1.Groups.Count]; // copy groups into array and remove from explorer barfor (int x = temp.Length - 1; x >= 0; x--) { temp[x] = ultraExplorerBar1.Groups[x]; ultraExplorerBar1.Groups.RemoveAt(x); } // reverse arrayArray.Reverse(temp); // add groups backfor (int x = 0; x < temp.Length; x++) { ultraExplorerBar1.Groups.Add(temp[x]);
// copy groups into array and remove from explorer bar
temp[x] = ultraExplorerBar1.Groups[x]; ultraExplorerBar1.Groups.RemoveAt(x);
temp[x] = ultraExplorerBar1.Groups[x];
ultraExplorerBar1.Groups.RemoveAt(x);
// reverse array
// add groups back
ultraExplorerBar1.Groups.Add(temp[x]);
} ultraExplorerBar1.EndUpdate();
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.
Thanks for your reply.
I'm now using the below as a workround and will submit this as a bug.
ultraExplorerBar1.BeginUpdate();UltraExplorerBarGroup[ temp = new UltraExplorerBarGroup[ultraExplorerBar1.Groups.Count]; SortedList<string,Control> controls = new SortedList<string,Control>();Control tempParent = new Control(); // copy groups into array and remove from explorer barfor (int x = temp.Length - 1; x >= 0; x--) {UltraExplorerBarGroup g = ultraExplorerBar1.Groups[x]; temp[x] = g; controls.Add(g.Key, g.Container.Controls[0]); controls[g.Key].Parent = tempParent; ultraExplorerBar1.Groups.RemoveAt(x); } // reverse arrayArray.Reverse(temp); // add groups backfor (int x = 0; x < temp.Length; x++) {UltraExplorerBarGroup g = temp[x]; ultraExplorerBar1.Groups.Add(g); controls[g.Key].Parent = g.Container; } tempParent.Dispose(); ultraExplorerBar1.EndUpdate();
SortedList<string,Control> controls = new SortedList<string,Control>();
temp[x] = g;
controls.Add(g.Key, g.Container.Controls[0]);
controls[g.Key].Parent = tempParent;
ultraExplorerBar1.Groups.Add(g);
controls[g.Key].Parent = g.Container;
tempParent.Dispose();