VB LISTBOX内容移动问题
我想把LIST1里面的内容用一个按钮控制移动到LIST2中,代码如下,就是当LIST2中为空内容0时,单击按钮COMMAND3时就把LIST1中的内容移动到LIST2中,...
我想把LIST1里面的内容用一个按钮控制移动到LIST2中,代码如下,就是当LIST2中为空内容0时,单击按钮COMMAND3时就把LIST1中的内容移动到LIST2中,但只能移动一次,请问下面的代码该怎样修改呢。望各位前辈能指导小弟,谢谢,刚入门VB!
Private Sub Command3_Click()
If List2.SelCount = 0 Then
List2.AddItem "1"
List2.AddItem "2"
List2.AddItem "3"
List2.AddItem "4"
List2.AddItem "5"
List1.Clear
End If
End Sub 展开
Private Sub Command3_Click()
If List2.SelCount = 0 Then
List2.AddItem "1"
List2.AddItem "2"
List2.AddItem "3"
List2.AddItem "4"
List2.AddItem "5"
List1.Clear
End If
End Sub 展开
2个回答
展开全部
从List1移动伍茄到List2的代码:
Private Sub Command3_Click()
Do While List1.ListCount >卖橘纳 0
List2.AddItem List1.List(0)
List1.RemoveItem (0)
Loop
End Sub
**************************************************************************
从List1复制到中没List2的代码(不重复):
Private Sub Form_Load()
For i = 1 To 5
List1.AddItem String(3, Chr(i + 48))
Next
List2.AddItem "333"
End Sub
Private Sub Command3_Click()
For i = 0 To List1.ListCount - 1
If Not inList(List1.List(i)) Then List2.AddItem List1.List(i)
Next
End Sub
Private Function inList(str As String) As Boolean
For i = 0 To List2.ListCount
If str = List2.List(i) Then
inList = True
Exit For
Else
inList = False
End If
Next
End Function
Private Sub Command3_Click()
Do While List1.ListCount >卖橘纳 0
List2.AddItem List1.List(0)
List1.RemoveItem (0)
Loop
End Sub
**************************************************************************
从List1复制到中没List2的代码(不重复):
Private Sub Form_Load()
For i = 1 To 5
List1.AddItem String(3, Chr(i + 48))
Next
List2.AddItem "333"
End Sub
Private Sub Command3_Click()
For i = 0 To List1.ListCount - 1
If Not inList(List1.List(i)) Then List2.AddItem List1.List(i)
Next
End Sub
Private Function inList(str As String) As Boolean
For i = 0 To List2.ListCount
If str = List2.List(i) Then
inList = True
Exit For
Else
inList = False
End If
Next
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询