Question : How to get the Drop down items of a ToolStripDropDownButton to remain open.

I have placed this control on a form and I fill the dropdownitems collection in code.  I have it setup so that the items show the check box when they are clicked, but when you click on it it closes.  I want it to stay open until the user either clicks off of the control or mouse out (mouse leave)

I tried setting the ToolStripDropDownButton.DrowDown.AutoClose=False, but that made it remain open all the time.  Then I tried using that with the ToolStripDropDownButton.MouseLeave event and setting the autoclose in this event to true, but that only worked if I mouse back over the button...

Thoughts?

Answer : How to get the Drop down items of a ToolStripDropDownButton to remain open.

You can do the following:

- Instead of directly add child items to ToolStripDropDownButton, delete it. Leave the ToolStripDropDownButton clean.

- Add a new ContextMenuStrip to the form and add your child items into the ContextMenuStrip. Don't forget to set to True the CheckOnClick property of each item if you want them to act as checkboxes.

- Set the Dropdown property of the ToolStripDropDownButton to the ContextMenuStrip just created.

- Add the following code in the Closing event of the ContextMenuStrip control:
Private Sub ContextMenuStrip1_Closing(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripDropDownClosingEventArgs) Handles ContextMenuStrip1.Closing
    If e.CloseReason = ToolStripDropDownCloseReason.ItemClicked Then e.Cancel = True
End Sub

With all this you'll get your context menu always open when the user clicks on individual items, but will work as usual in the rest of situations (click outside the menu to close, click on the button to close, etc).

Hope that helps.
Random Solutions  
 
programming4us programming4us