Friday, 9 August 2013

Disable all menu items

Disable all menu items

How to disable all menu items in context menu which contain separator item?
My approach:
For Each item As ToolStripMenuItem In ContextMenuStrip1.Items
item.Enabled = False
Next
work good if I haven't separator in menu but with separator I get error:
Unable to cast object of type 'System.Windows.Forms.ToolStripSeparator' to
type 'System.Windows.Forms.ToolStripMenuItem'.
How to disable all items in menu which contain separator item?

No comments:

Post a Comment