|
-
Aug 10th, 2005, 08:55 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Listbox Selection Question
I can't seem to figure this one out.
What I am trying to do is cycle through a large list of items in a ListBox and be able to get the text of whatever item is currently selected.
I have a listbox with multiselect enabled. I want it to go through a list of names and grab only the ones that are selected and add them to a second listbox.
Here is what I'm doing.
VB Code:
Dim i As Integer
Do until i = lstnames.ListIndex -1
If lstnames.Selected(i) = True then
lstdept.AddItem 'this is where I get stuck
End If
i = i + 1
Loop
I've tried using lstnames.Text, but that only keeps grabbing the first item selected.
I appreciate the help 
Thanks
-
Aug 10th, 2005, 08:58 PM
#2
Re: Listbox Selection Question
Unless I'm missing something, try this:
VB Code:
Dim i As Integer
Do until i = lstnames.ListIndex -1
If lstnames.Selected(i) = True then
lstdept.AddItem lstnames.list(i)
End If
i = i + 1
Loop
-
Aug 10th, 2005, 09:01 PM
#3
Re: Listbox Selection Question
I think even if you have selected many items lstnames.Selected(i) = True will actually be one only. You could try a listbox with a checkbox instead...
-
Aug 10th, 2005, 09:03 PM
#4
Thread Starter
Hyperactive Member
Re: Listbox Selection Question
 Originally Posted by dglienna
Unless I'm missing something, try this:
VB Code:
Dim i As Integer
Do until i = lstnames.ListIndex -1
If lstnames.Selected(i) = True then
lstdept.AddItem lstnames.list(i)
End If
i = i + 1
Loop
This returns an error saying invalid use of property.
Thanks tho
-
Aug 10th, 2005, 09:04 PM
#5
Thread Starter
Hyperactive Member
Re: Listbox Selection Question
 Originally Posted by dee-u
I think even if you have selected many items lstnames.Selected(i) = True will actually be one only. You could try a listbox with a checkbox instead...
I'm willing to try it if the other way is impossible.
What would I have to do different to the code I posted above for a checked listbox? I've never used it like that before 
Thanks
-
Aug 10th, 2005, 09:07 PM
#6
Re: Listbox Selection Question
 Originally Posted by dee-u
I think even if you have selected many items lstnames.Selected(i) = True will actually be one only. You could try a listbox with a checkbox instead...
Works for me 
This?
VB Code:
For i = 0 To List1.ListCount - 1
If List1.Selected(i) = True Then
list2.AddItem List1.List(i)
End If
Next
Has someone helped you? Then you can Rate their helpful post. 
-
Aug 10th, 2005, 09:09 PM
#7
Thread Starter
Hyperactive Member
Re: Listbox Selection Question
 Originally Posted by manavo11
Works for me
This?
VB Code:
For i = 0 To List1.ListCount - 1
If List1.Selected(i) = True Then
list2.AddItem List1.List(i)
End If
Next
Works like a charm!
Just what I wanted
Thank You
-
Aug 10th, 2005, 09:11 PM
#8
Re: Listbox Selection Question
 Originally Posted by manavo11
Works for me
This?
VB Code:
For i = 0 To List1.ListCount - 1
If List1.Selected(i) = True Then
list2.AddItem List1.List(i)
End If
Next
I stand corrected.
-
Aug 10th, 2005, 09:18 PM
#9
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
|