Hi,
I'm working on a application menu which uses 2 UltraExplorerBars. The first one has Outlook Navigation Pane style. The second one has ExplorerBar style, and is displayed in the ControlContainer of the first one, as shown below:
All groups for both ExplorerBars are created at runtime via code. When you click a bouton in the NavigationOverflowButtonArea of the 1st ExplorerBar (highlighted in green), the groups and items of the 2nd ExplorerBar are then created and the ExplorerBar is added to the ControlContainer of the 1st ExplorerBar, as you can see in the yellow area. This is done by the method
groupLevel1(counter).Container.Controls.Add(UltraExplorerBarLevel2)
When you click the button highlighted in red, the first level menu change. All the groups are deleted, and the control container is cleared:
groupLevel1(counter).Container.Controls.Clear()
UltraExplorerBarLevel1.Groups.Clear()
So it works fine the first time I click the "switch" button, as you can see in the right screenshot. But when I click again, to retrieve the state you can see in the left screenshot, I have the message "System.ObjectDisposedException: Cannot access a disposed object", when the program is trying to do:
So if someone understands my problem and can help me, it would be very nice.
Regards.
Olivier FALCY.
By default, the control referenced by the ControlContainer property is disposed of when the associated group is removed. The Groups collection exposes an overload of the Remove method which allows you to prevent disposal of the ControlContainer. The Clear method, however, does not provide this parameter, so you would have to use the Remove method to remove the groups (reverse iterate the collection and call Remove for each method).
Hi Brian,
Thank you for the answer. I'm always lost between the Remove, Dispose and Clear methods .
So I've used the Remove method as suggested, and now I've another error which occurs this time at the first attempt to construct the 2nd level menu (i.e when I pass from the left screenshot of my first message to the right one, not when I come back to the initial menu as I explained before).
The error message is "System.NullReferenceException, Object reference not set to an instance of an object".
It occurs at the end of the method fired by the SelectedGroupChanged event of the first UltraExplorerBar.
I can see that the menu is well created as shown in the right screenshot of my first message, and there is no code after since it's the end of the SelectedGroupChanged event, so I don't understand what causes this Fatal error.
May be it's because I remove the group (the "switch" button) which fires the SelectedGroupChanged event, in the method called by this event ?
I tried to keep the "switch" button (instead of removing it) when I rebuild the 1st level menu, but when I do that, the 2nd UltraExplorerBar is not displayed in the ControlContainer.
Is there a way to avoid the fatal error ?
Here is the .NET StackTrace, if it can help you:--> à Infragistics.Win.UltraWinExplorerBar.UltraExplorerBarGroup.DoHeaderClick() à Infragistics.Win.UltraWinExplorerBar.NavigationOverflowButtonUIElement.OnClick() à Infragistics.Win.ControlUIElementBase.ProcessMouseUpHelper(Object sender, MouseEventArgs e) à Infragistics.Win.ControlUIElementBase.ProcessMouseUp(Object sender, MouseEventArgs e) à Infragistics.Win.Utilities.ProcessEvent(Control control, ProcessEvent eventToProcess, EventArgs e) à Infragistics.Win.UltraControlBase.OnMouseUp(MouseEventArgs e) à Infragistics.Win.UltraWinExplorerBar.UltraExplorerBar.OnMouseUp(MouseEventArgs e) à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) à System.Windows.Forms.Control.WndProc(Message& m) à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) à System.Windows.Forms.Application.Run(Form mainForm)