check item in a checkedListBox

dubem1

Newcomer
Joined
Dec 5, 2002
Messages
20
I can't figure how to use the checkedlistBox control. Here is my situation.

When I load my form, I add ti the checkedListBox all the possible values. They are all unchecked and came from a DataTable.

Here are the values
ID Value
2045 ItemA
2342 ItemB
2434 ItemC
2342 ItemD

then when I load my record, it contains a collections of id of items to be checked.
Record 1 items to be checked 2045 and 2434
Record 2 items to be checked 2342

The checkedListBox use Indice!! I can't do anythin with indice. I have to deal with my ID

I hope I dont have to do a loop in my checklistbox and check if the id equal the record items collections id!!

Any idea?

Thanks
 
you can get checked items, but you still need to loop through the collection,
Visual Basic:
For x = 0 To Listbox1.Items.Count - 1
      If Listbox1.GetItemChecked(x) Then
           'you can retrieve the ID (or Value) from the Dataset/DataTable 
'(using the X as the Row in the Dataset/DataTable)
      End If
Next
 
No,
SetItemChecked use indice. Maybe I wasn't clear

Here is my four record added to the checkedListBox

ID Name
2045 ItemA
2342 ItemB
2434 ItemC
2342 ItemD

They are all, at first uncheked. If I want to check the second one, I will use CheckedListBox1.SetItemChecked(1, True). That's ok, but my problem is if I want to check the item corresponding to the Id 2434. I don't know it's position is the checkedListBox so I can't use SetItemChecked directly. I need to know first what's the indice(or if yout prefer the index) of the item corresponding to the id 2434. Id there a way to find my item from is ID without doing a loop and check all item one by one?

Thanks
 
Back
Top