Reputation: 212
I am adding MenuItems to my ContextMenu like this:
mnuContextMenu.MenuItems.Add("Delete", DeleteFile);
Now i want to disable this MenuItem, like this:
x.Enabled = false;
What MenuItem reference do I have to use for x?
Upvotes: 0
Views: 181
Reputation: 15237
You don't have anything to directly reference it. You could get it using the indexer of the MenuItems property:
mnuContextMenu.MenuItems[0].Enabled = false; // if it were the first item
or you could have a reference when creating it:
var deleteMenuItem = new MenuItem("Delete", DeleteFile);
mnuContextMenu.MenuItems.Add(deleteMenuItem);
and then you have the reference to use later:
deleteMenuItem.Enabled = false;
You may need to store it as a private data member of your class, rather than a local variable if you're planning to use it outside of your current function.
Upvotes: 1