checked listbox check all

H

Hrvoje Voda

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

Hrcko
 
T

Tim Wilson

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();
 
H

Hrvoje Voda

What should I put instead of x<25?

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

Hrcko
 
T

Tim Wilson

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

checked list box 3
ckecked listbox 4
checked item 1
list box checked 2
listbox search 1
list box fill 3
check disabled 3
Access Cannot select items in listbox 1

Top