【发布时间】:2022-04-04 18:10:27
【问题描述】:
使用 VB6
在一个表单中,2个列表框名称分别为list1、list2和4个按钮名称>、>>、
I want to add the list1 selected items to list2
I want to remove the selected items from list2 to list1
如何做到这一点。
需要 Vb6 代码帮助
【问题讨论】:
使用 VB6
在一个表单中,2个列表框名称分别为list1、list2和4个按钮名称>、>>、
I want to add the list1 selected items to list2
I want to remove the selected items from list2 to list1
如何做到这一点。
需要 Vb6 代码帮助
【问题讨论】:
通常,您的方法是循环遍历源 ListBox 中所有项目的索引值。如果您要移动 ListBox 上的所有项目,那么对于每个项目,您将在目标 ListBox 上调用 AddItem 方法(使用索引值来检索源 ListBox 上当前项目的文本)。然后,您将调用 ListBox RemoveItem 方法从源 ListBox 中删除相同的项目。
如果您只移动选定的项目,那么您仍将循环遍历所有索引值,但您将使用源 ListBox 上每个项目的Selected 属性来确定该项目是否被选中。如果是,请使用上述步骤移动该项目。
但是,您需要执行的具体操作会有所不同,具体取决于您在 ListBox 上设置一些属性的方式。您会发现有用的资源是the discussion on ListBoxes at thevbprogrammer.com。查看示例:使用两个列表框添加和删除项目部分;它包括您想要做什么的示例。
【讨论】:
在 VBA 中从 List1 中添加 List2
Private Sub CMDAddOne_Click()
On Error GoTo Err_cmdAdd_Click
If Me.List1.ListIndex >= 0 Then
Me.List2.AddItem (Me.List1.ItemData(Me.List1.ListIndex))
End If
Exit_cmdAdd_Click:
Exit Sub
Err_cmdAdd_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_Click
End Sub
从 List2 中删除
If Me.List2.ListIndex >= 0 Then
Me.List2.RemoveItem Me.List2.ListIndex
End If
【讨论】: