Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How to check items if they are in a listbox

Okay, I'm not sure how to explain this correctly but I'll give it a shot.

On Form_Load I am enumerating values in a reg key and then displaying all the reg values that are in the key into a listbox. After that I want to check items (in a checkedlistbox) that are the same as those in the listbox. Is this even possible? If so please help!

Thanks in advance
[384 byte] By [jobartley515] at [2007-11-11 8:08:57]
# 1 Re: How to check items if they are in a listbox
Sure, it's possible. What problem(s) are you having?
Phil Weber at 2007-11-11 21:47:56 >
# 2 Re: How to check items if they are in a listbox
:) I don't know how to do it...
jobartley515 at 2007-11-11 21:48:56 >
# 3 Re: How to check items if they are in a listbox
What don't you know how to do:

- Enumerate registry keys
- Populate listbox
- Find matching items in CheckedListBox
- Check items in CheckedListBox

?
Phil Weber at 2007-11-11 21:50:06 >
# 4 Re: How to check items if they are in a listbox
I know how to:

-Enumerate Values
-Populate Listbox
-Check listbox items

I don't know how to:

-(I want to) Check checkedlistbox items if the items are in the listbox (which has the enumerated values) :)

I hope this clears things up a bit...
jobartley515 at 2007-11-11 21:51:06 >
# 5 Re: How to check items if they are in a listbox
Try this:

For Each item As Object In lstBox.Items
Dim index As Integer = lstChecked.FindStringExact(item.ToString)
If index >= 0 Then
lstChecked.SetItemChecked(index, True)
End If
Next
Phil Weber at 2007-11-11 21:52:05 >
# 6 Re: How to check items if they are in a listbox
Thanks, it works great!!!!!!!
jobartley515 at 2007-11-11 21:52:59 >