VB6.0中删除listbox选中内容的问题
这是一个用commandbutton来实现listbox中内容的删除代码PrivateSubCommand1_Click()DimaAsIntegerWhileList1...
这是一个用commandbutton来实现listbox中内容的删除代码Private Sub Command1_Click()Dim a As IntegerWhile List1.SelCount > 0For a = 0 To List1.ListCount - 1If List1.Selected(a) = True ThenList1.RemoveItem List1.ListIndexEnd IfNext aExit ForWendEnd Sub大家快帮我看一下哪里有错误,一运行就卡住了.....
展开
展开全部
因为删除的时候改变了List1.ListCount.修改一下For语句即可:
For a = List1.ListCount - 1 To 0 Step -1
另外也不需要Exit For,我帮你改了下代码:
Option Explicit
Private Sub Command1_Click()
Dim a As Integer
If List1.SelCount > 0 Then
For a = List1.ListCount - 1 To 0 Step -1
If List1.Selected(a) Then List1.RemoveItem a
Next
End if
End Sub
For a = List1.ListCount - 1 To 0 Step -1
另外也不需要Exit For,我帮你改了下代码:
Option Explicit
Private Sub Command1_Click()
Dim a As Integer
If List1.SelCount > 0 Then
For a = List1.ListCount - 1 To 0 Step -1
If List1.Selected(a) Then List1.RemoveItem a
Next
End if
End Sub
展开全部
你是不是想删除选中的项目,可以参考一下我的代码:
Private Sub Command1_Click()
Dim i As Integer
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) Then
List1.RemoveItem i
End If
Next
End Sub
Private Sub Command1_Click()
Dim i As Integer
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) Then
List1.RemoveItem i
End If
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2022-01-20
展开全部
If ListBox1.ListCount >= 1 Then
If ListBox1.Selected(ListBox1.ListIndex) Then ListBox1.RemoveItem ListBox1.ListIndex
End If
listbox1 为列表框名称
ListBox1.ListIndex 为列表框所选值的行号
ListBox1.Selected() 判断所选的值是否为真(True)
ListBox1.RemoveItem 删除所选的行
If ListBox1.Selected(ListBox1.ListIndex) Then ListBox1.RemoveItem ListBox1.ListIndex
End If
listbox1 为列表框名称
ListBox1.ListIndex 为列表框所选值的行号
ListBox1.Selected() 判断所选的值是否为真(True)
ListBox1.RemoveItem 删除所选的行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
If List1.SelCount > 0 Then
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) Then List1.RemoveItem i
Next
End If
End Sub
If List1.SelCount > 0 Then
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) Then List1.RemoveItem i
Next
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim a As Integer
While List1.SelCount > 0
For a = 0 To List1.ListCount - 1
If List1.Selected(a) = True Then
List1.RemoveItem
List1.ListIndex
End If
Next a
Exit ForWend
End Sub
Dim a As Integer
While List1.SelCount > 0
For a = 0 To List1.ListCount - 1
If List1.Selected(a) = True Then
List1.RemoveItem
List1.ListIndex
End If
Next a
Exit ForWend
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询