checked listbox check all

  • Thread starter Thread starter Hrvoje Voda
  • Start date Start date
H

Hrvoje Voda

After I fill checked listbox with data, I would like to checked all items in
list ?

Hrcko
 
You can actually set the check state while you're adding the item(s), in
code.

this.checkedListBox1.BeginUpdate();
for (int x = 0; x < 25; x++)
{
this.checkedListBox1.Items.Add(x.ToString(), CheckState.Checked);
}
this.checkedListBox1.EndUpdate();

If you really need to set all the check states after you have added the
items, then you can use the SetItemChecked method.

this.checkedListBox1.BeginUpdate();
for (int x = 0; x < 25; x++)
{
this.checkedListBox1.Items.Add(x.ToString());
}
for (int x = 0; x < this.checkedListBox1.Items.Count; x++)
{
this.checkedListBox1.SetItemChecked(x, true);
}
this.checkedListBox1.EndUpdate();
 
What should I put instead of x<25?

I tried listBox.Items.Count but it doesn't work!

Hrcko
 
I'm was just loading the CheckedListBox with some data. So you can either
set the check state when you're adding the items to the Items collection or
loop through and set them afterwards. There should be nothing wrong with
"checkedListBox1.Items.Count" (of course, insert the name of your control).
 
Back
Top