1

Simple question:

I can .Select a ToolStripItem (like, if i want a preselected option when opening a context menu strip) but i cannot seem to find a way to set .Selected to false or somehow deselect it!

Is it possible?

John Arlen
  • 6,539
  • 2
  • 33
  • 42
Istrebitel
  • 2,963
  • 6
  • 34
  • 49

3 Answers3

3

There is private method ClearAllSelections in ToolStrip class, which removes selections from items. You can invoke it via reflection:

MethodInfo method = typeof(ToolStrip).GetMethod("ClearAllSelections", BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(yourContextMenuStrip, null);

All selections will be removed.

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
0

You're looking for the Checked property?

public void mnuUncheck()
{
    foreach (ToolStripMenuItem Item in mnuStripMain.Items)
    {
       Item.Checked = false;
    }
}
Erre Efe
  • 15,387
  • 10
  • 45
  • 77
  • Checked is a "v" sign near a menu strip item, right? I'm talking about the selection, what happens when you hover over a context menu item. – Istrebitel Apr 26 '12 at 05:40
0

Taking the approach of Sergey, there is also an internal method on the ToolStripItem which you could call:

MethodInfo methodInfo = typeof(ToolStripItem).GetMethod("Unselect", BindingFlags.NonPublic | BindingFlags.Instance);
methodInfo.Invoke(yourToolStripItem, null);
cannero
  • 41
  • 3