Hi there,
I have a checkedlistbox on my windows form which is databound to a
dataview.
If i do a "myControl.Items.Count", it returns zero, but it displays
all my items as checkbox items.
I cant figure out a way how to loop through my control and deselect/
select all when the items.count always = 0.
However, when i manually add the items, the Items.Count works okay.
Any help appreciated in how i can deselect items in a databound
checkedlistbox.
thanks,
Paul
Andrew Backer - 20 Aug 2007 22:01 GMT
Not sure why the count would be zero (I don't check it there), but I assume
it is because the items are actually coming form DataBinding and not fromthe
control's internal item list. You could look at either your binding source
for the count, or the dataview's count property.
Hope this helps, but we all do it a little differently:
To Clear all selected items:
lstRecipient.SelectedItems.Clear()
To check all items you could probably use something like this:
For Each itm As DataRowView In me.lstRecipients.Items
lstRecipients.SetItemCheckState( lstRecipient.Items.IndexOf(itm),
CheckState.Checked
Next
There are other ways to do this, I am sure, but I do it this way because
I have other work to do in determining who is/isn't selected (which I cut
out), so I actually make a temporary list of items.
// Andrew
> Hi there,
>
[quoted text clipped - 11 lines]
> thanks,
> Pau