|
-
Apr 21st, 2003, 08:00 PM
#1
Thread Starter
Addicted Member
For or Do statement for Listboxes in VB.NET [Resolved]
I have a listbox (currently project is in VB.NET but could do in VB6. The listbox contains a list of items. What would the syntax be for a For or Do statement that would perform an action for each item that is checked\highlighted?
IE. 6 names in a listbox, 3 are highlighted. What would the statement look like if I wanted a msgbox to pop-up for each of their names. Below is the syntax for VB6, I cannot figure out the syntax for VB.NET.
VB Code:
Dim n As Long, nCount As Long
nCount = List1.ListCount - 1
For n = 0 To nCount
If List1.Selected(n) Then
MsgBox List1.List(n)
End If
Next
Last edited by jlegan; Apr 21st, 2003 at 08:33 PM.
-
Apr 21st, 2003, 08:15 PM
#2
Try a for each loop and use the selecteditems collection of the listbox.
VB Code:
Dim obj As Object
For Each obj In ListBox1.SelectedItems
MsgBox(obj.ToString)
Next
-
Apr 21st, 2003, 08:33 PM
#3
Thread Starter
Addicted Member
Thanks, I changed in to List1.CheckedItems because I changed it to a CheckedListBox.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|