Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the checked state of a ToolStripItem in Winforms?

When I look it up, they list it as having a .Checked property. But both in Visual Studio and on msdn, it doesn't list any kid of Checked property.

ContextMenuStrip menu = new ContextMenuStrip ( );
var menuItem = menu.Items.Add ( "CheckedItem" );
//menuItem.Checked?

Is there a way to do this?

like image 618
Joan Venge Avatar asked Oct 21 '11 03:10

Joan Venge


People also ask

What is ToolStripMenuItem?

ToolStripMenuItem(String, Image, ToolStripItem[]) Initializes a new instance of the ToolStripMenuItem class that displays the specified text and image and that contains the specified ToolStripItem collection.

How do I add items to MenuStrip C#?

We can add items to a MenuStrip at design-time from Properties Window by clicking on Items Collection as you can see in Figure 4. When you click on the Collections, the String Collection Editor window will pop up where you can type strings. Each line added to this collection will become a MenuStrip item.


1 Answers

You need to cast to ToolStripMenuItem:

((ToolStripMenuItem)menuItem).Checked = true;
like image 87
Jeff Ogata Avatar answered Oct 05 '22 07:10

Jeff Ogata