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?
Here's my code to remove the buttons from the root tool collection. The error occurs when I call the Remove method on the tools collection.
If TypeOf objToolbarsManager.Tools(i) Is Infragistics.Win.UltraWinToolbars.ButtonTool Then
If objButtonTool.Key.ToUpper.Trim.StartsWith("APPLICATIONMENU_") Or objButtonTool.Key.ToUpper.Trim.StartsWith("QUICKACCESSTOOLBAR_") Or objButtonTool.Key.ToUpper.Trim.StartsWith("POPUPMENU_") Or objButtonTool.Key.ToUpper.Trim.StartsWith("RECENTLYUSEDMENU_") Then
'remove the tool from the base tool collection...
objToolbarsManager.Tools.Remove(objButtonTool)
End If
Next
'need to refresh the toolbar since the merge has already happened...
objToolbarsManager.RefreshMerge()
Its hard to say from the description. Is it possible to post the section of code which attempts to remove the tools?