Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toolstrip with check button group

I'd like to have a toolstrip with some buttons on it (WinFroms/c#/.net4). I'd like to have the clicked button be checked and all others unchecked, so I want to have only the clicked button checked, all the others unchecked.

I know toolstrip button has checkedonlclick property, but when I click one button, others may be also checked. In good old VB6 there was an automatic solution for this problem: buttongroup on toolbar. Is there any similar in Winfoms?

Or should I handle it from code?! Switch all other buttons to unchecked state when one button is checked? If so, then it would not be my favourite solution...

like image 590
Tom Avatar asked Jun 17 '11 17:06

Tom


1 Answers

Call this code on the toolStripButton_Click events and you should get the desired result.

   foreach (ToolStripButton item in ((ToolStripButton)sender).GetCurrentParent().Items)
   {
       if (item == sender) item.Checked = true;
       if ((item != null) && (item != sender))
       {
          item.Checked = false;
       }
   }
like image 152
KreepN Avatar answered Sep 27 '22 18:09

KreepN