title: C# checkedlistbox with radiobutton behavior
body: <p>The last couple of days I've been looking for a solution to this problem but haven't found a proper solution yet. I've made a WinForm with a checkedlistbox that must behave as a radiobuttongroup. I know it's not preferable but I haven't chosen this myself. I'm trying to expand my knowledge on WinForm so I grabbed a program and try to mimic the behavior so please stay with me.</p>
  <p>Radiobutton properties I want in my checkedlistbox:</p>
  <ul>
  <li>You can only check one item. (Easy to do, see code below)</li>
  <li>One item is always checked. (This is the source of my problem)</li>
  <li>When you click the checkbox/bullet it checks with one click, clicking on the text doesn't change anything. (I've figured that one out as well)</li>
  </ul>
  <p>Checkedlistbox properties I need:</p>
  <ul>
  <li>Selectable text behind checkbox. (Used for renaming and deleting items in list)</li>
  </ul>
  <p>I works most of the time except when a item is selected and another item is unchecked. That's when every item in the list can be unchecked.</p>
  <p>This is the code for the ItemCheck event.</p>
  <pre><code>private string _checkedName = &quot;&quot;;
  bool _autorizeCheck {get; set;}
  
  private void OnItemCheck(object sender, ItemCheckEventArgs e)
  {
              var list = sender as CheckedListBox;
  
              #region//Click checkbox
              if (!_authorizeCheck)
              {
                  e.NewValue = e.CurrentValue;
              }
              #endregion
  
              #region//Radiobutton config
              if (e.CurrentValue == CheckState.Unchecked)
              {
                  for (int i = 0; i &lt; list.Items.Count; i++)
                  {
                      if (i != e.Index)
                      {
                          _checkedName = list.Items[e.Index].ToString();
                          list.SetItemChecked(i, false);
                      }
                  }
              }
              else if(e.CurrentValue == CheckState.Checked &amp;&amp; _checkedName == list.Items[e.Index].ToString())
              {
                  if (list.CheckedItems.Count == 1)
                  {
                      e.NewValue = e.CurrentValue;
                  }
              }
              #endregion
  }
  </code></pre>
  <p>This is the code for clicking the checkbox:</p>
  <pre><code>private void OnMouseDown_checkedListBox(object sender, MouseEventArgs e)
          {
              #region//Check if checkbox is clicked
              var checkedListBox = sender as CheckedListBox;
              var location = checkedListBox.PointToClient(Cursor.Position);
              for (int i = 0; i &lt; checkedListBox.Items.Count; i++)
              {
                  var rec = checkedListBox.GetItemRectangle(i);
                  rec.Width = 16;
  
                  if (rec.Contains(location))
                  {
                      _authorizeCheck = true;
                      bool newValue = !checkedListBox.GetItemChecked(i);
                      checkedListBox.SetItemChecked(i, newValue); 
                      _authorizeCheck = false;
  
                      return;
                  }
              }
              #endregion
          }
  </code></pre>