Question DGV and ContextMenu

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
Could someone please check this for me?

New project, add a DataGridView to a form.

Add a ContextMenuStrip, and add the following :-

Insert
Move
(separator)
Delete

Under "Insert", add the following children
One row
Two rows

Under "Delete", add the following children
Delete row
Delete ALL rows

With "Insert", set the Enabled property to False

Link the ContextMenuStrip to the DGV.

Run the project, and right click on the DGV. You cant click on Insert as it's disabled. If you quickly go down and hover over Delete (so that it's children are NOT shown) and then go back to Insert, the children are still not shown.

However, if you hover over Delete so the children are shown, and then go back to Insert, the children are shown :eek: :eek: - and will run events if clicked on :eek:

Any suggestions (other than to loop through all the children and set them to disabled :D)
 

Attachments

  • contextmenustrip.jpg
    contextmenustrip.jpg
    92.7 KB · Views: 40
This caused me another problem today :mad:

What's the most efficient way of disabling every item on a contextmenu (ie looping through all sub-levels as well) ?
 
Weird bug. Use a recursive method to set Enabled for item and all childs.
VB.NET:
Sub SetEnabled(ByVal item As ToolStripMenuItem, ByVal state As Boolean)
    item.Enabled = state
    For Each child As ToolStripMenuItem In item.DropDownItems
        SetEnabled(child, state)
    Next
End Sub
 
Thanks John :D
 
Back
Top