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
944
Accessing Popup Menu items
posted

Hi,

I have a toolbar (Toolbar1), which has a Popup Menu tool (Print). The Print menu has a report (Report1) available that I need to disable under some conditions, however I have not been able to access the menu item.

I have tried:

ultraToolbarsManager.Toolbars["Toolbar1"].Tools["Report1"].SharedProps.Enabled = false;

However an exception is thrown saying "Key not found. Parameter Name: Key".

Without the above line of code, the program runs fine, so I have narrowed it down to how I am trying to access the tool itself. I am able to successfully disable the Print tool itself with:

ultraToolbarsManager.Toolbars["Toolbar1"].Tools["Print"].SharedProps.Enabled = false;

I just have not worked out how to access the tools under the Print Popup Menu.

How can I do this.

Cheers
Jason

Parents
  • 44743
    Verified Answer
    posted

    The tool actually exists in two places in your example and you can access it through either way. When you create a tool, a 'root' tool is created on the toolbars manager. If you add that tool to a menu or a toolbar or the ribbon, an 'instance' tool is created in those locations. Each tool must have one root and can have zero or more instances throughout the toolbars manager (this is why all tools have SharedProps and InstanceProps: SharedProps affect all tools instances, and InstanceProps only affect a specific tool instance). An instance of the Report1 tool in your example exists on the Print menu, so you could get that instance like this:

     

    PopupMenuTool printMenuInstance = (PopupMenuTool)ultraToolbarsManager.Toolbars["Toolbar1"].Tools["Print"];

    printMenuInstance.Tools["Report1"].SharedProps.Enabled = false;

     

    Alternatively, you can just get the property on the root tool:

     

    ultraToolbarsManager.Tools["Report1"].SharedProps.Enabled = false;

Reply Children
No Data