I am having a problem adding a PopupMenuTool to an already existing PopupMenuTool. I am unable to post the code that I am using but I will try to explain.
I have an UltraWinGrid object (myWinGrid)
I have an UltraToolbarsManager object (mTBMgr).
I have a PopupMenuTool popMenu7 = new PopupMenuTool ("gridPopup").
- the popMenu7 PopupMenuTool contains a bunch of buttons
popMenu7.Tools.AddRange ( ToolBase[] { buttonTool40, buttonTool41, .....});
- the popMenu7 PopupMenuTool is added to the UltraToolbarsManager object
mTBMgr.Tools.AddRange ( ToolBase[] { button50, popMenu7 , button 51,.....} );
(All of this is logic is in the InitializeComponent method of my form)
I have a event handler to handle the OnMouseUp event for the grid (myWinGrid). Here is the code for that event
protected void myWinGridOnMouseUp(sender, e)
{
if (e.Button.Eqauls(MouseButton.Right)
PopupMenuTool contextMenu = mTBMgr.Tools["gridPopup"] as PopupMenuTool ;
PopupMenuTool newContext = new PopupMenuTool("Columns");
newContext.SharedProps.Caption = "Columns";
mTBMgr.Tools.Add(newContext );
contextMenu.Tools.AddTool("Columns");
contextMenu.ShowPopup();
}
When I run this code, the "Columns" popup menu is not displaying in the popMenu7 menu. If I step through the code and I examine the contents of the mTBMgr and popMenu7, the "Columns" popup menu exists in the Tools collection but it is not displaying.
We have 2 versions of Infragistics at our Company, version 8 (8.1.20081.1000) and version 10 (10.1.20101.1007). The code I have listed above works when I use version 8 of Infragistics but it does not work when I use version 10 of Infragistics.
There is a proxy ContextMenuStrip that is trying to open when you right click on a control. Internally, the UltraToolbarsManager is detecting this and showing the popMenu7 instead. In older versions, this was a ContextMenu instead of a ContextMenuStrip. My guess is Microsoft changed the order of events with regard to the context menu opening and the MouseUp event. So when you add a tool to popMenu7 in the MouseUp event, it has already started displaying itself as a context menu.
Regardless of event order, trying to do this is MouseUp event is not recommended, specifically because of the unpredictable order. It is better to handle the UltraToolbarsManager.BeforeToolDropdown event. If the tool being dropped down is a context menu, the SourceControl property of the event args will be the Control that was right-clicked and the Tool property will be a root tool.
Thanks for the update. I was playing around a little bit with the UltraToolbarsManager.BeforeToolDropdown event and I wasnt able to accomplish what I wanted to accomplish. Let me explain to you what I want to do and maybe you can help me out. I have the following 2 items: a PopupMenuTool (popmenu7) filled with ButtonTools and an UltraGrid (grid) full of data. When the user right-clicks in the grid, I want to add a PopupMenuTool to the already exists PopupMenuTool (popmenu7). This newly added PopupMenuTool will contain all of the columns headers that appear in the grid (a check mark will appear next to all columns that are visible). The user uses this PopupMenuTool to hide/show columns in the grid.
So what I was trying to do in the UltraToolbarsManager.BeforeToolDropdown event, was to create an instance of the PopupMenuTool (popmenu7) and then add a submenu that has all of the columns that appear in the grid (or should I say in the underlying datasource, which is a list of custem datatypes). Is this something I can accomplish in the UltraToolbarsManager.BeforeToolDropdown event
You shouldn't be creating an instance of popMenu7 in the BeforeToolDropdown event. You should be adding tools to the e.Tool property on the event args if it is popMenu7 and e.SourceControl is your grid control. That will tell you that the grid was right-clicked. Of course, you will need to cast e.Tool to a PopupMenuTool so you can access the Tools collection and add tools to it.
OK, I tried modifying the e.Tool property in the BeforeToolDropdown event and it did not work. Here is what I did:
In the Form_Load event, I set
mToolbarsManager.SetContextMenuUltra(this, "gridPopup");
- "gridPopup" represents popMenu7 which I mentioned in a previous Post.
In the InitializeComponent method I create an event handler to handle the BeforeToolDropdown event
mToolbarsManager.BeforeToolDropDown += new BeforeToolDropDownEventHandler(mToolbarsManager_BeforeToolDropdown)
In the mToolbarsManager_BeforeToolDropdown event I have the following code:
PopupMenuTool newContext = new PopupMenuTool ("Columns");
mToolbarsManager.Tools.AddRange( new Infragistics.Win.UltraWinToolbars.ToolBase[] { newContext });
(e.Tool as PopupMenuTool ).Tools.AddTool("Columns");
When I run this code, the Context menu (PopupMenu --> popMenu7) does not contain the new "Columns" PopupMenu. When I step through the debugger, the "Columns" PopupMenu appears in the mToolbarsManager.Tools collection but it is not being displayed. Can you modify e.Tool to add in a new PopupMenu? Do you have any ideas on how I can accomplish what I want to accomplish?
I can't reproduce the problem. I've attached a sample that I think demonstrates what you described, except I applied the context menu to the Form instead of a grid. Am I missing something?
@tronoski.
Just for curiosity. Are you using a MDI child with merged toolbars?
We have a similar behavior as long as this.UltraToolbarsManager1.MdiMergeable = True (default) is set. When we switch to this.UltraToolbarsManager1.MdiMergeable = False in child form Form_Load event then the dynamic context shows up.
Dominik, there is no need to disable merging to get this to work. If you are using a merged toolbars manager and you add tools to PopupMenuTools defined on the child, you must call RefreshMerge() on either the parent of child managers. The parent will not track changes in the child to update merged tools when changes occur.
A lot of changes have been made since then. My guess is there was probably a bug in 2007.1 where the toolbars manager was erroneously picking up some changes in the child but not all. It was probably fixed between then and now. I will contact DS about your open issue.
Thanks Mike,
this solved my issue. Maybe you can tell this your teammates :) At least the one who is responsible for my open issue.
But why is this necessary now in 2010.3? Because in 2007.1 I don't need to call RefreshMerge(). It just works. Maybe you can give me an explanation.
I did a short source diff between 2007.1 and 2010.3 and I saw that there was something regarding merging at PopupTool.cs. But I didn't dig deeper into it.