|
-
January 13th, 2004, 04:41 PM
#1
Context Menu
I am trying to display a different context menu for different tree nodes. I can distinguish what node has been selected but the context menu is displaying the context menu for the last node selected. After searching the forums I saw that you have to place:
treeView1.SelectedNode = treeView1.GetNodeAt(e.X, e.Y);
in the mousedown event. I still have the same result. I stepped through the mouse down code to ensure it is working and it is.
*********************
On mouse up I verify the right mouse button:
*********************
if(e.Button == MouseButtons.Right)
{
*********************
I then see what type of node by checking the .Tag property:
*********************
TreeNodeTypeStruct newTreeNodeTypeStruct = new TreeNodeTypeStruct();
newTreeNodeTypeStruct = (TreeNodeTypeStruct) treeView1.SelectedNode.Tag;
if(newTreeNodeTypeStruct.getTreeNodeTypeStruct() == TreeNodeType.System)
{
*********************
I create the context menu:
*********************
MenuItem miAddZone = new MenuItem("Add Zone",
new EventHandler(OnAddZoneNode));
cm1.MenuItems.Add(miAddZone);
//EventHandler ehAddZone = new EventHandler (OnAddZoneNode);
//cm1.MenuItems.Add("Add Zone", ehAddZone);
ContextMenu = cm1;
*********************
The event method:
*********************
void OnAddZoneNode(object obj, EventArgs ea)
{
TreeNode newNode = treeView1.SelectedNode.Nodes.Add("Zone");
TreeNodeTypeStruct myTreeNodeTypeStruct = new TreeNodeTypeStruct(TreeNodeType.Zone);
newNode.Tag = myTreeNodeTypeStruct;
}
*********************
During debug the functions are stepping through but the wrong menu is being displayed.
Any advice??
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|