如何将项目从一个列表框移动到另一个列表框 [英] How to move the items from one listbox to another listbox

查看:54
本文介绍了如何将项目从一个列表框移动到另一个列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 VB6

在一个表单中,2个列表框名称为list1、list2和4个按钮名称>、>>、<、<<

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

I want to add the list1 selected items to list2
I want to remove the selected items from list2 to list1

如何做到这一点.

需要 Vb6 代码帮助

Need Vb6 code Help

推荐答案

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

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 AddItem method 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 RemoveItem method to remove the same item from your source ListBox.

如果您只移动选定的项目,那么您仍然会遍历所有索引值,但您会使用 Selected 源列表框中每个项目的属性,以确定该项目是否被选中.如果是,请使用上述步骤移动项目.

If you're moving only selected items, then you'd still loop through all index values but you'd use the Selected property 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 上设置一些属性.您会发现有用的资源是 thevbprogrammer 上的关于列表框的讨论.com.查看示例:使用两个列表框添加和删除项目;它包括您想要做什么的示例.

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 ListBoxes over at thevbprogrammer.com. Look at the section Example: Adding and Removing Items with Two ListBoxes; it includes examples of what you want to do.

这篇关于如何将项目从一个列表框移动到另一个列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆