Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable menu items in the ContextMenuStrip?

I have options like "Add", "Delete" and "Update" in my ContextMenuStrip, which should pop up when the user right clicks on a ListView.

How can I make the Update menu disabled if there are no items in the list view?

like image 381
Prasad MV Avatar asked Mar 01 '13 22:03

Prasad MV


2 Answers

Use the ContextMenuStrip.Opening event..

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

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

like image 191
VDALLCO Avatar answered Oct 22 '22 03:10

VDALLCO


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);
  }
}
like image 35
LarsTech Avatar answered Oct 22 '22 02:10

LarsTech