vb.net中控件ListBox的多项选择与输出!

2024年11月15日 21:49
有3个网友回答
网友(1):

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

网友(2):

把listbox的selectionmode
属性设置为multiextended就可以了
如果是代码控制就是
listbox1.selectionmode=selectionmode.multiextended

网友(3):

'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