Question:
Visual Basic 2005. Need to have listbox 1 and 2 items selected show in listbox 3 with button push. ?
anonymous
2008-10-27 06:01:02 UTC
Ok. Working with 3 listboxes and 1 button. I need to have what i select at runtime from listbox 1 and 2 show up in 3. None of my code is working. Please help? I need code suggestions. Thanks.
Four answers:
kryzchek79
2008-10-27 09:51:41 UTC
In your button's click event handler:



Dim NewText as string



NewText = String.Format("{0} {1}", ListBox1.Text, ListBox2.Text)



ListBox3.Items.Add(NewText)





[EDIT]



You're going to need to be more specific. What errors do you get when you build the project?
Captain Mephisto
2008-10-27 06:08:36 UTC
This is not clear. Do you just want to take the current selections in listboxes 1 and 2 and put these two entries into listbox 3?



I created a form with 3 listboxes and a button. I added data to the listboxes.



Private Sub Command1_Click()

List3.Clear

List3.AddItem List1.Text

List3.AddItem List2.Text

List3.ListIndex = 0

End Sub



Private Sub Form_Load()

List1.ListIndex = 0

List2.ListIndex = 0

End Sub



I initialize the selected items in list1 and list2 in form_load.

When the button is pushed I clear list3 and add the selected items from list1 and list2 and then set the first entry to be selected.



Does this help you?



This works fine in VB6. what error do you get?



I repeat, what error do you get and what is it that you are trying, exactly?



looked it up, maybe this will do it:

list3.items.add(List1.items(list1.selectedindex))
anonymous
2008-10-27 08:46:01 UTC
This should get you started, make sure the Multiselect property is set for Listbox 1 and 2



Dim i As Integer





If List1.ListIndex = -1 Then

Exit Sub

End If



For i = List1.ListCount - 1 To 0 Step -1



If List1.Selected(i) = True Then

List3.AddItem List1.List(i)

End If



Next i
winkels
2016-09-28 04:30:29 UTC
in case you're looking a thank you to create a label at runtime, you will locate the syntax for turning out to be a label from scratch by ability of viewing the code seen Studio generates once you create a label interior the varieties fashion designer.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...