|
-
May 17th, 2003, 09:48 PM
#1
Thread Starter
New Member
How do I display everything in a listbox with a msgbox?
I'm using Visual Basics.NET 2002.
My form has 1 ComboBox, 1 ListBox and 3 Buttons.
Private Sub form_load...
ComboBox.Items.Add("Cherry")
ComboBox.Items.Add("Grape")
ComboBox.Items.Add("Mango")
End Sub
Private Sub ComboBox1_SelectedIndexChanged...
ListBox.Items.Add(ComboBox.SelectedItem)
End Sub
Private Sub ButtonClearList_Click
ListBox.Items.Clear
End Sub
Private Sub ButtonRemoveFruit_Click
If ListBox.SelectedIndex = -1 Then
MsgBox("No fruit was choosen.")
Else
Dim I As Integer = ListBox.SelectedIndex
ListBox.Items.RemoveAt(I)
End If
End Sub
Private Sub ButtonShowAllMyFruits_Click...
'After I picked, 1 Cherry, 2 Grapes and 4 Mangos from the ComboBox, _
'my chosen fruits will appear in the ListBox.
'How do I show all my choices in a message box?
'I want the message box to say "You picked 1 cherry, 2 grapes and 4 mangos.")
End Sub
-
May 18th, 2003, 12:07 PM
#2
Sleep mode
Declare three variables and store in them selected items from comboboxes and listbox accordingly . then just use this "
messagebox.show(vari1 & " , " & vari2 & " , " & vari3 & " , "
or follow the formula you like .
-
May 18th, 2003, 12:37 PM
#3
Lively Member
I wasn't sure from your description what was in the listbox??
You can loop through the contents of the listbox like this:
Dim o As Object
Dim str As String = ""
For Each o In ListBox1.Items
str += o.ToString
Next
MsgBox(str)
Inside the loop you could count them, or do whatever.
HTH
G
-
May 18th, 2003, 12:53 PM
#4
PowerPoster
Originally posted by ggprogram
I wasn't sure from your description what was in the listbox??
You can loop through the contents of the listbox like this:
Dim o As Object
Dim str As String = ""
For Each o In ListBox1.Items
str += o.ToString
Next
MsgBox(str)
Inside the loop you could count them, or do whatever.
HTH
G
Use a string builder object though, it will be slightly faster. System.Text namespace I do believe.
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
|