How to move the items from one listbox to another listbox

烈酒焚心 提交于 2021-02-20 04:25:47

问题


Using VB6

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

How to do this.

Need Vb6 code Help


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/8102735/how-to-move-the-items-from-one-listbox-to-another-listbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!