dubem1 Posted March 25, 2003 Posted March 25, 2003 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 Quote
Moderators Robby Posted March 25, 2003 Moderators Posted March 25, 2003 you can get checked items, but you still need to loop through the collection, 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 Quote Visit...Bassic Software
dubem1 Posted March 25, 2003 Author Posted March 25, 2003 I want to check the items I don't think this code is doing checking More help please Quote
Negative0 Posted March 26, 2003 Posted March 26, 2003 This is what you need: CheckedListBox1.SetItemChecked(IndexOfItem, True) Quote
dubem1 Posted March 26, 2003 Author Posted March 26, 2003 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 Quote
Moderators Robby Posted March 26, 2003 Moderators Posted March 26, 2003 Get the row position you need from the Dataset/DataTable, it will correspond with the row of the Listbox. Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.