选择ListBox中的最后一个项目:
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
删除选中的项目和他以下的项目:
i = ListBox1.SelectedIndex
For j = 1 To ListBox1.Items.Count - i
ListBox1.Items.RemoveAt(i)
Next
选择ListBox中的最后一个项目
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
删除
i = ListBox1.SelectedIndex
For j = ListBox1.Items.Count - i to i Step -1
ListBox1.Items.RemoveAt(i)
Next
注解:??
可使用ToolTip 类
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Me.ListBox1
.Items().Add("111")
.Items().Add("222")
.Items().Add("333")
.Items().Add("444")
.Items().Add("555")
End With
End Sub
'选择操作
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.ListBox1().SetSelected(Me.ListBox1.Items.Count - 1, True)
End Sub
'删除操作
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
For i = 0 To Me.ListBox1.Items.Count - 1
If Me.ListBox1.GetSelected(i) = True Then
Me.ListBox1.Items.RemoveAt(i)
Exit For
End If
Next
选择ListBox中的最后一个项目:
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
删除选中的项目和他以下的项目:
i = ListBox1.SelectedIndex
For j = 1 To ListBox1.Items.Count - i
ListBox1.Items.RemoveAt(i)
Next