Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
i have a checkboxlist with 3 items...but i want to check only one item at a time...how to do this in c#?
Posted 21-Jan-14 1:27am
Comments
Jas24 at 21-Jan-14 6:44am
   
Try it in RadioButtonList.
Member 10276220 at 21-Jan-14 6:44am
   
no buddy...i need it in checkboxlist
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Use SelectedIndexChanged event of checkedListBox1 .
Refer following code.
 
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
       {
           int iSelectedIndex = checkedListBox1.SelectedIndex;
           if (iSelectedIndex == -1)
               return;
           for (int iIndex = 0; iIndex < checkedListBox1.Items.Count; iIndex++)
               checkedListBox1.SetItemCheckState(iIndex, CheckState.Unchecked);
           checkedListBox1.SetItemCheckState(iSelectedIndex, CheckState.Checked);
       }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

use for loop like this
 

for(int i=0;i<chklist.items.count;i++)>
{
    if(chkList.GetItemChecked(i) == true)
    {
        //true
    }
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Try this:
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    int selNdx = checkedListBox1.SelectedIndex;
 
    foreach(int cbNdx in checkedListBox1.CheckedIndices)
    {
        if(cbNdx != selNdx)
        {
            checkedListBox1.SetItemChecked(cbNdx, false);
        }
    }
}
By using the 'CheckedIndices property of the CheckedListBox, you know which items are checked, and can test only those. Using this code, you don't have to deal with the fact that each Item in the CheckedListBox is Type 'object.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
Member 10276220 at 21-Jan-14 7:08am
   
i want it in c#
KARTHIK Bangalore at 21-Jan-14 7:20am
   
ok.. kindly check after some time...

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 21 Jan 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100