1
votes

Sorry if this has been answered before but I searched the site and couldn't find anything that answers my question.

I can move selected items between my listboxes but how do i move all items from one listbox and add them to another one? if possible I would like to append them to the bottom rather than replacing the items in the other listbox.

The coding i use to move specific items is

 Dim selectedItems = (From i In ListBox1.SelectedItems).ToArray()

    For Each selectedItem In selectedItems
        ListBox2.Items.Add(selectedItem)
        ListBox1.Items.Remove(selectedItem)
    Next

I cant answer my own question for some reason but many thanks Heinzi, for anyone else having the same problem the following coding should help you.

Dim selectedItems = (From i In ListBox1.Items).ToArray()

For Each selectedItem In selectedItems
    ListBox2.Items.Add(selectedItem)
    ListBox1.Items.Remove(selectedItem)
Next
2
Since you cannot answer your own question, I've moved my comment to an answer so that you can mark it (and, thus, mark this question as answered). - Heinzi

2 Answers

2
votes

You can use the same code, but iterate through ListBox1.Items instead of ListBox1.SelectedItems:

Dim itemsToMove = ListBox1.Items.ToArray()  ' to make a copy of the list of items

For Each item In itemsToMove
    ListBox2.Items.Add(item)
    ListBox1.Items.Remove(item)
Next
0
votes

Try this to move all items - Worked 100%

For Each item As String In ListBox1.Items
            ListBox2.Items.Add(item.ToString)
        Next