vb 关于List

来源:百度知道 编辑:UC知道 时间:2024/06/04 06:29:20
Private Sub Command8_Click()
Dim S As String
Dim i As Integer
S = (Text4(0).Text)
List2.AddItem S
List2.ListIndex = List2.ListCount - 1
end sub
这是向List2添加内容的代码,现在想让List2最多输入10行,即使在继续添加也还是前十行也就是第11行不显示了,并且弹出MsgBox "不能超过10个"
Private Sub Command8_Click()
Dim S As String
Dim i As Integer
S = (Text4(0).Text)List2.AddItem S
List2.ListIndex = List2.ListCount - 1
For i = 0 To 9
If List2.ListIndex > 9 Then
List2.ListIndex = i
MsgBox "不能超过10个"
End If
Next
End Sub
我这么写当List2超过10行时他还是显示,该怎么改

Private Sub Command1_Click()
Dim S As String
Dim i As Integer
S = (Text1.Text)
List1.AddItem S
List1.ListIndex = List1.ListCount - 1
If List1.ListIndex >= 10 Then
MsgBox "不能超过10个"
List1.RemoveItem 10
End If
Debug.Print List1.ListIndex
End Sub