vb 一定条件下删除listbox中的部分内容

当label1caption=50时,删除listbox.list中最后20项

在窗口上放置一个list1、command1

Private Sub Command1_Click()
Label1.Caption = 50
'方法一、删最后一个,删20次
' If Label1.Caption = 50 Then
' Dim i As Integer
' i = 20
' While i > 0
' List1.RemoveItem List1.ListCount - 1
' i = i - 1
' Wend
' End If
‘方法二、开始删之前确定 倒数第20个的 序号 (从零开始),每次都删这个固定位置的
'当最后一个的序号 比这个固定位置的序号小的时候就是删完 最后20项了
If Label1.Caption = 50 Then
Dim i As Integer
i = List1.ListCount - 20
While List1.ListCount - 1 >= i
List1.RemoveItem i
Wend
End If
End Sub

Private Sub Form_Load()
Dim i As Integer
For i = 1 To 25
List1.AddItem i
Next
End Sub
温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜