Hi,
Not sure this is going to be possible, but...
Within one of our projects we have our own inherited version of the ultragrid with various customisations. It is used exclusively through the project when a grid is needed. Typically when used on forms it will have a context menu attached to it, hosted as part of an ultraToolbarsManager. This is set via the "ContextMenuUltra on...." property. We would like to add a standard menu entry to all of our grids, and ideally this would be handled entirely within the grid, to reduce the impact on the rest of the project. This is what I would like to be able to do, all within our grid class (that inherits from the ultragrid):
1) Look for the attached context menu
2) Dynamically create a new entry at the bottom of that menu
3) Wire an event handler to the new entry so that pressing it can be handled within our grid code
Does that seem possible?
Kevin
Hello ,
Yes you could build-in custom context menu to your class derived from UltraGrid. So you should add UltraToolbarsManager to your class deride form UltraGrid , and to add predefined items. Also you will need collection which will keep Extended tools which could be added at run time. Also you should design at least to events for the grid, one which will occurs before context menu drop down, it will be a cancelable event which will allows you to add additional tools to the context menu. Second which will occurs when any of the extended tool is clicked. I’ve implemented this suggestion in a small demonstrative sample, please see attached zip and let me know if this is what you are looking for. Please feel free to modify my code based on your custom needs.
I hope that this will helps you.
Thanks, I'll download the project and take a look
Thanks for that. I've taken a look and I can see what you are doing. One thing I may be missing though. Our forms typically define their own context menus for the grid, using a popup menu hosted on an ultratoolbarsmanager hosted on the form. Originally my problem was how to get the grid to add a menu item to this menu defined at the form level, but now I think my problem is how to let the form add its context menu items to the menu that is now defined within the grid. Does that make sense?
Hello,
I am just checking about the progress of this issue. Let me know If you need my further assistance on this issue?
Thank you for using Infragistics Components.
In windows form Control class has a method FindForm() retrieves the form that the control is on
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.findform(v=vs.110).aspx
so once you have accessed the owning form, you could use reflection in order to access IContainer field of the form where UltraToolbarsManager is passed. You could use code like:
Form f = this.FindForm();
FieldInfo componentsField = f.GetType().GetField("components", BindingFlags.NonPublic | BindingFlags.CreateInstance | BindingFlags.Instance);
IContainer components= componentsField.GetValue(f) as IContainer;
UltraToolbarsManager t = components.Components.Cast<IComponent>().FirstOrDefault(c => c is UltraToolbarsManager) as UltraToolbarsManager;
That's not a million miles from the solution I'd come up with. The only little niggle is that in an ideal world I'd like to see this working without the need to update all of the forms in the application (of which there are quite a few). This would require the grid to be able to identify the menu that is currently attached to it though, in order to avoid the form having to pass that into the grid, and I've not found a way to obtain that from the grid. I'm thinking I might need to access the grid's containing control iteratively until I find the form, look for an ultraToolbarsManager and then iterate through its extended properties to find the one that is applied to the grid. It seems a bit dirty though. Hmm, we have a base form class within the application, if I did it from there and called a method like the one you've defined in your sample, it would feel a bit cleaner....
Thank you for clarifying your issue.
So what I could suggest you based on my sample is to implement method TransitToContextMenu() method, which could remove tolls from existing PopupMenuTool and to add them to another (you cannot move tools from One ToolbarsManager to another, if you do not remove them from the source one). I’ve implemented this idea in my sample and I hope that this will helps you.