I will have some sort of nodes for a treeview as follows
Root |-> some.txt(A text file which was added at runtime) |->Child(child for some.txt) |-> child1(child for child)
I designed my context menu with some options as New and Remove
What i need is when i righclick on Root, child or child i would like to disable the Remove option
For a ContextMenu, you can handle the ContextMenu.Popup event and enable/disable menu options before the menu is shown.
For a ContextMenuStrip, you can do the same using the Opening event.
For example, if you use the Menu item Tag property to determine if remove is supported (This is just for the example). You can do some thing like this
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
if ((int)treeView1.SelectedNode.Tag == 1)
{
removeToolStripMenuItem.Enabled = true;
}
else
{
removeToolStripMenuItem.Enabled = false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With