I am dynamically adding button tools to the root tool collection and to the QuickAccess toolbar in my app. I am allowing the user to click the Customize button so they can turn off a button tool. That command seems to remove the item from the QuickAccessToolbar, but it doesn't remove the tool from the root tool collection. This makes sense because they are able to go back in and turn the tool on again if they choose.
When they close the form, I am looping through the tools and am trying to manually delete the tools I added, but I get an "object is not an instance of an object" error when I come upon a tool that the user turned off. What is the proper way to remove an item from the root tool collection after the user has removed it from the QuickAccessToolbar?
In that case, you may just have to wait for the hotfix containing the fix for your submitted issue.
Mike:
I have tried this code as well, but it just doesn't seem like the tool is being removed from the Tools collection properly.
Rich
'clear out the QuickAccessToolbar too...
If TypeOf objToolbarsManager.Ribbon.QuickAccessToolbar.Tools(i) Is Infragistics.Win.UltraWinToolbars.ButtonTool Then
'remove the tool from the application menu contextmenu tools...
objToolbarsManager.Ribbon.QuickAccessToolbar.ContextMenuTools.Remove(objButtonTool)
'remove the tool from the application menu...
objToolbarsManager.Ribbon.QuickAccessToolbar.Tools.Remove(objButtonTool)
'remove the tool from the base tool collection...
objToolbarsManager.Tools.Remove(objButtonTool)
End If
I'm still not sure what is causing the issue, but from the stack trace, I would guess the tool is in the ContextMenuTools collection of the QuickAccessToolbar. Try removing the tool from that collection before removing it from the toolbars manager's Tools collection. That might work around the issue.
Here's the exception detail:
System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object." Source="Infragistics2.Win.UltraWinToolbars.v8.1" StackTrace: at Infragistics.Win.UltraWinToolbars.ToolsCollectionBase.InternalRemove(ToolBase tool, Boolean notifyListeners) at Infragistics.Win.UltraWinToolbars.ToolsCollectionBase.LogicallyRemoveTool(ToolBase tool, Boolean notifyListeners, Boolean allowRemoveForTemporaryToolbar) at Infragistics.Win.UltraWinToolbars.ToolsCollectionBase.RemoveAt(Int32 index) at Infragistics.Win.UltraWinToolbars.ToolsCollection.RemoveAt(Int32 index) at Infragistics.Win.UltraWinToolbars.UltraToolbarsManager.Infragistics.Win.UltraWinToolbars.IToolsCollectionOwner.OnToolRemovedFromCollection(ToolBase tool, ToolsCollectionBase toolsCollection) at Infragistics.Win.UltraWinToolbars.ToolsCollectionBase.InternalRemove(ToolBase tool, Boolean notifyListeners) at Infragistics.Win.UltraWinToolbars.ToolsCollectionBase.LogicallyRemoveTool(ToolBase tool, Boolean notifyListeners, Boolean allowRemoveForTemporaryToolbar) at Infragistics.Win.UltraWinToolbars.ToolsCollectionBase.RemoveHelper(ToolBase tool, Boolean honorReadOnlyStatus, Boolean allowRemoveForTemporaryToolbar) at Infragistics.Win.UltraWinToolbars.RootToolsCollection.Remove(ToolBase tool) at E2SS80.frmFormTemplate.ClearApplicationMenu(UltraToolbarsManager& objToolbarsManager) in c:\E2SS80\E2SS_Win\Forms\Base Forms\frmFormTemplate.vb:line 318 at E2SS80.frmNavigator.frmNavigator_Activated(Object sender, EventArgs e) in c:\E2SS80\E2SS_Win\Forms\Miscellaneous Forms\Navigator Forms\frmNavigator.vb:line 805 at System.EventHandler.Invoke(Object sender, EventArgs e) at System.Windows.Forms.Form.OnActivated(EventArgs e) at System.Windows.Forms.Form.set_Active(Boolean value) at System.Windows.Forms.Form.ActivateMdiChildInternal(Form form) at System.Windows.Forms.Form.WmMdiActivate(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DefMDIChildProc(IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) at System.Windows.Forms.Form.DefWndProc(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam) at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam) at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp) InnerException:
This definately looks like a bug then. I would recommend submitting the issue to the support group: http://es.infragistics.com/gethelp.
The Remove method does a lot of processing, so its tough to say what is actually causing the issue, but if you want to post a stack trace of the error which shows the methods called by Remove in the toolbars assembly when the error occurs, I may be able to determine what is causing the issue and suggest a workaround if I see one.