
' Determine if the currently selected item in the ListBox
' is the item displayed at the top in the ListBox.
If listBox1.TopIndex <> listBox1.SelectedIndex Then
' Make the currently selected item the top item in the ListBox.
listBox1.TopIndex = listBox1.SelectedIndex
End If
' Remove all items before the top item in the ListBox.
Dim x As Integer
For x = listBox1.SelectedIndex - 1 To 0 Step -1
listBox1.Items.RemoveAt(x)
Next x
' Clear all selections in the ListBox.
listBox1.ClearSelected()
End Sub 'RemoveTopItems
listBox1.SelectedIndex 设置选中的项!
for (int i = 0 i < listBox1.Items.Count i++){
listBox1.SelectedItem = listBox1.Items[i]
}
首先要将listBox的selectionMode属性设置为MultiSimple或者MultiExtended后执行上述代码即可,不过如果你只是想做列表中的多项选择功能的话推荐用CheckedListBox控件,更加方便
欢迎追问
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)