vba 如何将项目从一个列表框移动到另一个列表框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8102735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 14:27:26  来源:igfitidea点击:

How to move the items from one listbox to another listbox

vbavb6

提问by Gopal

Using VB6

使用 VB6

In a form, 2 listbox name as list1, list2 and 4 buttons name >, >>, <, <<

在一个表单中,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

How to do this.

这该怎么做。

Need Vb6 code Help

需要 Vb6 代码帮助

回答by Jay Riggs

Generally, your approach will be to loop through the index values of all items in your source ListBox. If you're moving all items on the ListBox then for each item you'd call the AddItemmethod on your destination ListBox (using the index value to retrieve the text of the current item on your source ListBox). You would then call the ListBox RemoveItemmethod to remove the same item from your source ListBox.

通常,您的方法是遍历源列表框中所有项目的索引值。如果您要移动 ListBox 上的所有项目,那么对于每个项目,您将调用目标 ListBox 上的AddItem方法(使用索引值检索源 ListBox 上当前项目的文本)。然后,您将调用 ListBox RemoveItem方法从源 ListBox 中删除相同的项目。

If you're moving only selected items, then you'd still loop through all index values but you'd use the Selectedproperty for each item on the source ListBox to determine if the item is selected. If it is, use the steps above to move the item.

如果您只移动选定的项目,那么您仍会遍历所有索引值,但您将使用源 ListBox 上每个项目的Selected属性来确定是否选择了该项目。如果是,请使用上述步骤移动项目。

Specifics on what you need to do varies however, depending on how you've set a few properties on your ListBoxes. A resource you'll find useful is the discussion on ListBoxesover at thevbprogrammer.com. Look at the section Example: Adding and Removing Items with Two ListBoxes; it includes examples of what you want to do.

但是,您需要做什么的细节会有所不同,这取决于您如何在 ListBox 上设置一些属性。您会发现有用的资源是thevbprogrammer.com上关于 ListBoxes 的讨论。查看示例:使用两个列表框添加和删除项目;它包括您想要做什么的示例。