In my application, every UltraGrid has a "GridController" class that is responsible of the grid management ( Fill & Set datasource, InitializeLayout, all grid events, ...).
I want to set context menu to my grids. Some context menu options are the same for all grids ( Add rows, delete rows, ...) and some are grid specific.
Context menu options in a grid may also depends on which band is selected. Some row values may also affect which menu options is enabled/visible.
I want the context menu options to be accessible with keyboard shortcut. It is possible that while in a grid, a particular shortcut does something, and while in another grid, does something else.
Ok, now here is a specific situation: I have a form with 2 ultratabs, each one having an UltraGrid. I would like each UltraGrid (GridController) to be responsible to create (at runtime) its context menu options, and before showing the context menu,assign the enabled/visible properties of tools depending on the selected rows.
Based on this scenario, I'm wondering what is the recommended way to create the ultratoolbarsmanager ?
1- Only one ultratoolbarsmanager created in the form and shared by both Ultragrid. In that case, I'm concerned about events conflict between the two grids (toolclick, shortcut,..).
2- Each Ultragrid (GridController) has it's own ultratoolbarsmanager created at run-time. In that case, what is the proper way to create ultratoolbarsmanager at run-time ? Does it absolutly need a container to be docked in ?
3- Any other suggestion is welcomed.
Thanks,
Guillaume
guilmori said:And do you recommend using one toolbars manager for the whole application, or one in each form ?
I would recommend one toolbars manager for each form.
guilmori said:Regarding the BeforeShortcutKeyProcessed event, is it correct that a tool which is Enabled = false (Enabled is only for root tool, right ?) will not trigger the event when the shortcut key is pressed ?
This is correct.
guilmori said:This seems to work, but I was wondering if my approach is correct.
It sounds ok...if it works, I would continue using it. The other approach you could take is to move all code which enabled/disables tools to a helper method. Call it from both the BeforeToolDropdown and the BeforeShortcutKeyProcessed.
Many thanks Mike, I'll try what you suggest.
And do you recommend using one toolbars manager for the whole application, or one in each form ?
Regarding the BeforeShortcutKeyProcessed event, is it correct that a tool which is Enabled = false (Enabled is only for root tool, right ?) will not trigger the event when the shortcut key is pressed ?
This create a problem for me as I assign all the menu tools enabled state inside the BeforeToolDropdown event. So for example, "Tool1" is available on grid's row #1, but not on row #2. If I right-click on row #2, the menu is shown and the "Tool1" is disabled. Now if I select row #1, and press the "Tool1" shortcut, it will not respond, as the tool is still disabled.
To overcome this problem, I re-enable all menu's tools in the AfterToolCloseup event. Then, in the BeforeShortcutKeyProcessed event, I call my BeforeToolDropdown code to assign the tools enabled state, next, if e.Tool.EnabledResolved == false, set e.Cancel = true, and finally re-enable all menu's tools, so they respond to the next shortcut. This seems to work, but I was wondering if my approach is correct.
Kind Regards,
Guillaume.
I would recommend using one toolbars manager. Assign each grid the same popup menu as their context menu. In the BeforeToolDropdown event of the toolbars manager, check the SourceControl of the event args. If it is one of you grids, call off to a method on that grid's GridController and pass it the PopupMenuTool instance on the Tool property of the event args. This method on the GridController should populate the Tools collection of the PopupMenuTool based on the grid it controls as well as it's current state. As for handling shortcut keys, you can handle the BeforeShortcutKeyProcessed event on the toolbars manager to enable/disable any tools necessary for the currently active grid. In the ToolClick event, you would probably want to determine the currently active grid again and call off to tool click processing code defined on it's GridController.