Click here to Skip to main content
16,017,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
string[] values = label1.Text.Split(',');

       // foreach (ListView d in checkedListBox1.Items)
       //   {

       for (int x = 0; x < values.Length; x++)
       {
           if (checkedListBox1.Items.ToString() == values[x])
           {
               //checkedListBox1.Items[x].
           }
           //    if (d.ToString() == values[x])
           //    {

           //        label2.Text  = label2.Text + ","+ d;
           //    }
           //}
Posted
Updated 1-Apr-14 20:37pm
v2

1 solution

You should modify your code like this:
C#
 for(int i = 0; i < checkedListBox1.Items.Count; i++)
 {
  checkedListBox1.SetItemChecked(i, false);//First uncheck the old value!
  //
  for (int x = 0; x < values.Length; x++)
  {
           if (checkedListBox1.Items[i].ToString() == values[x])
           {
               //Check only if they match! 
               checkedListBox1.SetItemChecked(i, true); 
           }
  }
}
 
Share this answer
 
v2
Comments
Member 10285877 2-Apr-14 5:42am    
Now sir this error come " InvalidArgument=Value of '3' is not valid for 'index'.
Parameter name: index"
Member 10285877 2-Apr-14 5:46am    
Sir now work it properly thanku
Member 10285877 2-Apr-14 6:09am    
sIR IT ONLY cOMPARISON first index found then its goes next index otherwise not check the item of checbox list
Raul Iloc 2-Apr-14 6:28am    
So it is working or not?
If not please describe clear what data do you have in your "label1" and what do you want to be checked!
Member 10285877 3-Apr-14 0:42am    
sir my label data is : i,am,sumit,kaplesh and i check only am,kaplesh so please suggest what i do

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