Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Moderators
Posted

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

Visit...Bassic Software
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...