Question Multiple selection ListBox click order

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
Is this what you mean/want?
Code:
'Class variable
Dim myArr As New List(of String)
'listbox1.SelectedIndexChanged Event:
Dim i As String = listBox1.SelectedItem
myArr.Add(i)
'then in a button click for 1 example: 
For Each i as string in myArr
textbox1.Text &= i & ", "
Next
But it really depends on where you want to send it!
 

sisquo76

Active member
Joined
Dec 1, 2008
Messages
28
Location
Bosnia and Herzegovina
Programming Experience
3-5
Is this what you mean/want?
Code:
'Class variable
Dim myArr As New List(of String)
'listbox1.SelectedIndexChanged Event:
Dim i As String = listBox1.SelectedItem
myArr.Add(i)
'then in a button click for 1 example: 
For Each i as string in myArr
textbox1.Text &= i & ", "
Next
But it really depends on where you want to send it!
Thanks man, That's what I need. I will export it to text file. I know how. Thanks again!
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,324
Location
Norway
Programming Experience
10+
Set the SelectionMode to MultiSimple, this also makes keeping track of the click order much simpler:
Code:
Private clickorder As New List(Of Integer)

Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
    Dim itemIndex As Integer = Me.ListBox1.IndexFromPoint(e.Location)
    If itemIndex <> ListBox.NoMatches Then
        If Me.ListBox1.GetSelected(itemIndex) Then
            clickorder.Add(itemIndex)
        Else
            clickorder.Remove(itemIndex)
        End If
    End If        
End Sub
At any time to have a look at the order the currently selected items was selected:
Code:
Dim builder As New System.Text.StringBuilder
builder.AppendLine("the items was selected in this order:")
For Each ix As Integer In clickorder
    builder.AppendFormat("index {0}: {1}" & vbNewLine, ix, Me.ListBox1.Items(ix))
Next
MessageBox.Show(builder.ToString)
 
Top Bottom