Swanand Swanand -4 years ago 168
C# Question

Show checkbox for Context MenuStrip or Context Menu of a button

I am designing a logging feature in which User can select which event he wants to log.
On clicking button, I am showing such type of menu:
Context Menu on Button click

User can select multiple Events so I need to show "Check Mark" infront of the selected option when user clicks on it.

I am unable to find any options like "Checked" or "CheckOnClick" as mentioned in this question.

I tried with ContextMenu and ContextMenuStrips but couldn't achieve Checkboxes.
Any Suggestions??

Answer Source

Don't see any of your code so I don't know how you create this menu. But in the most general terms, here is how you access the Checked property.

((ToolStripMenuItem)contextMenuStrip.Items[0]).Checked = true; //false;
((ToolStripMenuItem)contextMenuStrip.Items[1]).Checked = true; //false;
((ToolStripMenuItem)contextMenuStrip.Items[2]).Checked = true; //false;

You can assign them as either true or false. If you have named your ToolStripItems, then you can access them directly rather than going to the Items array.

contextMenuStrip.event1.Checked = true; //false;

As you can see, I am using a ContextMenuStrip.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download