Hi,
You have not included the code to show what u are doing. However I guess you must be changing the context menu in the AfterSelect event of the treeview. However the selectednode property does not change when we right click on the node. So u will have to set the selectednode to the 1 which u have rightclicked in the mousedown event . Now the code in the AfterSelect event will work.
Here is a sample code listing:
private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
if(treeView1.SelectedNode.Text=="Sales")
treeView1.ContextMenu=salesMenu;
else
treeView1.ContextMenu=childMenu;
}
private void treeView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(treeView1.GetNodeAt(e.X, e.Y)!=null)
{ treeView1.SelectedNode= treeView1.GetNodeAt(e.X, e.Y);
}
}
If u do not wish to change the SelectedNode on right click just move the code where u are assigning the context menu in AfterSelect to MouseDown event.