How to create a contextualized context menu?
-
Hi, I have a TreeView which will be used like the Visual Studio project explorer. In Visual Studio, there are different context menu for different kind of items. How can i do that? As i can see, i can only use one context menu per control. Thx, Nuno
-
Hi, I have a TreeView which will be used like the Visual Studio project explorer. In Visual Studio, there are different context menu for different kind of items. How can i do that? As i can see, i can only use one context menu per control. Thx, Nuno
sinosoidal wrote:
As i can see, i can only use one context menu per control.
There is no restriction like that. You can add multiple context menus and set them using the Form.ContextMenu property. Also, you can access the current context menu using the ContextMenu property dynamically add or remove items from it.....
-
Hi, I have a TreeView which will be used like the Visual Studio project explorer. In Visual Studio, there are different context menu for different kind of items. How can i do that? As i can see, i can only use one context menu per control. Thx, Nuno
In a handler for the NodeMouseClick event of the TreeView, remove all the context menu items and add items that are specific for the particular node:
treeView.NodeMouseClick+=treeView_NodeMouseClick;
...
private void treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if((e.Button & System.Windows.Forms.MouseButtons.Right)!=0)
{
contextMenu.Items.Clear();
//add some items (e.Node is the node that's being right-clicked)
contextMenu.Items.Add(e.Node.Name + " 1");
contextMenu.Items.Add(e.Node.Name + " 2");
}
}--Justin Microsoft MVP, C#
C# / Web / VG.net / MyXaml expert currently looking for (telecommute) contract work![^]
-
sinosoidal wrote:
As i can see, i can only use one context menu per control.
There is no restriction like that. You can add multiple context menus and set them using the Form.ContextMenu property. Also, you can access the current context menu using the ContextMenu property dynamically add or remove items from it.....
Ahh! I see! Cool Thx, Nuno