Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
MessageBox.Show(ListBox1.SelectedItem.ToString)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For i As Integer = 0 To 10
ListBox1.Items.Add(i.ToString)
Next
End Sub
'''''''选择多项
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For i As Integer = 0 To 10
ListBox1.Items.Add(i.ToString)
Next
ListBox1.SelectionMode = SelectionMode.MultiSimple
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim item
For Each item In ListBox1.SelectedItems
MessageBox.Show(item.ToString)
Next
End Sub
把listbox的selectionmode
属性设置为multiextended就可以了
如果是代码控制就是
listbox1.selectionmode=selectionmode.multiextended
'listbox的MultiSelect设置为1
Private Sub Command1_Click()
Cls
For i = 1 To List1.ListCount - 1
If List1.Selected(i) = True Then
Print List1.List(i)
End If
Next
End Sub