I am trying to select multiple items in a listbox and place the values into a textbox on another form in vb6. I just can't seem to get it right. If I select 3 items, it only returns the last item selected? Please help!
Listboxes
Collapse
X
-
Tags: None
-
It should look something like this as far as I can tell. This is not my code, I found this information here:
Code:Dim objX as Object For Each objX in lstBox.SelectedItems 'Do Something Next -
-
If you are using VB 6 or below the problem is there isnt a .SelectedItems Method, that is .NET and the link is for .NET, something like this could be of help to youOriginally posted by fauxanaduIt should look something like this as far as I can tell. This is not my code, I found this information here:
Code:Dim objX as Object For Each objX in lstBox.SelectedItems 'Do Something Next
Going on the basis that your other form is called "MyFormName " which you can change lol, The text box you are transfering the information to is called "Text1" and the List
Comments are included so that you can determine what each line of code does, (Turns green when in the code explorer screen), but i hope this helps youCode:Private Sub Command1_Click() Dim i As Integer MyFormName.Text1.Text = "" 'Clear The Text Box For Use MyFormName.Text1.MultiLine = True 'Make Sure The Text Box Is Multiline 'Loop through the items in the List Box (Named: List1) For i = 0 To List1.ListCount - 1 If List1.Selected(i) = True Then 'If The List Item Is Selected With MyFormName 'With The Other Form .Text1.Text = .Text1.Text & List1.List(i) 'Add The Selected Text .Text1.Text = .Text1.Text & vbCrLf 'Next Line After The Added Text End With 'End With The Other Form End If Next MyFormName.Show 'Show the other form. End Sub
Brief Rundown:
For i = 0 to List1.listcount - 1 : The listbox's list starts at 0, where as the count does not, so to stop it getting confused - 1 from the list count
vbCrLf: Next line
With MyFormName: means you dont have to type out MyFormName.Text 1.Text everytime you want to do something with an object on that particular form.
Hope This Helps
Kind Regards
Devon.Comment
-
-
Its quite alright, glad to help i know when i struggle for things i want people to help me so i return the favour when i can, The comments should give you all the guidance you need with it, pretty self explanatory...
Sorry for the abruptness, was a bit hungover this afternoon :P but i looked and thought... Im sure it doesnt have SelectedItems, unless ive been going about it the wrong way all this time rofl.Originally posted by fauxanaduSorry, I missed the vb6 part. Thank you for the correction, devon.
Kind Regards
DevonComment
-
Yesterday morning I had my right half of my body kinda jerk, and felt really bad all of a sudden. I was somewhat disoriented but tried to go about my daily routine. I eventually went to the hospital, but I missed many simple things yesterday due to being disorented, so I appologize for making mistakes yesterday by answering questions when I should have been going to a doctor.Comment
Comment