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
560
Remove Tool from PopupMenu at Run-time
posted

I have a context menu that I created at design-time.  At run-time, I want to remove specific tools that do not belong in the context menu given a specific situation.  So, for a given invocation of the context menu, how to I remove a tool from the menu?

 I have tried:

Dim tool As Infragistics.Win.UltraWinToolbars.ToolBase

tool = Me.UltraToolbarsManager1.Tools("myToolToRemove") 

Me.UltraToolbarsManager1.Toolbars("myContextMenu").Tools.Remove(tool)

 However, this (and other derivations thereof) don't seem to get the tool off of the context menu.  Can anyone tell me what I am doing wrong?

Thanks in advance,

Keith

  • 44743
    Verified Answer
    posted

    The code you have posted will not work because the context menu is a tool, not a toolbar. Try using the following code instead:

     CType(Me.UltraToolbarsManager1.Tools("myContextMenu"), PopupMenuTool).Tools.Remove(tool)

    You can also write the code this way if you have to do multiple removes (so you don't have to do multiple casts):

    Dim contextMenu As PopupMenuTool = CType(Me.UltraToolbarsManager1.Tools("myContextMenu"), PopupMenuTool)
    contextMenu.Tools.Remove(tool)
    ' Remove addition tools