Click here to Skip to main content
15,907,493 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello to all,
i m working on checklistbox.
i want only to mark one item at a time from checklistbox and if user select another checkbox ,the previous checkbox get unmarked.
how could i do that.
Posted
Comments
Herman<T>.Instance 3-Aug-11 4:13am    
use the oncheck changed event and iterate over the checkboxes

You can use a RadioButtonList.

However, if you still want to continue with a check box, see http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/5333cdf2-a669-467c-99ae-1530e91da43a[^].
 
Share this answer
 
Keep a trace of the currently checked item in a variable.

In the SelectedIndexChanged handler, reset the currently checked item, and set the new one.

C#
if (SelectedIndex >= 0)
{
    checkedListBox1.SetItemChecked(SelectedIndex, false);
}
SelectedIndex = checkedListBox1.SelectedIndex;
checkedListBox1.SetItemChecked(SelectedIndex, true);
 
Share this answer
 
Set the checklistbox's CheckOnClick attribute as True on form load.
Use the SelectedIndexChanged event like so:

private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
   if (checkedListBox1.GetItemChecked(checkedListBox1.SelectedIndex))
   {
      foreach (int item in checkedListBox1.CheckedIndices)
      {
         if(item != checkedListBox1.SelectedIndex)
            checkedListBox1.SetItemChecked(item, false);
      }
   }
}
 
Share this answer
 
You can use Radio Button's for best you of it.........
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900