How to disable menu items in ContextMenuStrip?

I have options such as Add, Delete, and Refresh in my ContextMenuStrip, which should appear when the user right-clicks on the ListView.

How to disable the update menu if there are no items in the list view?

+6
source share
2 answers

You can try using the MouseDown event:

void listView1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { updateToolStripMenuItem.Enabled = (listView1.Items.Count > 0); } } 
+4
source

Use the ContextMenuStrip.Opening event.

 if (ListBox1.Items.Count == 0) { ItemAToolStripMenuItem.Enabled = false; } 

http://i.imgur.com/8DlqvDZ.png

+7
source

All Articles