2
votes

I have two list boxes, one on the left and once on the right. Ideally, I want the user to be able to select whatever data he wants from the left list box, and press the "Add" button for the items he selected to be displayed in the second list box in the order they choose the item.

If they select item 2 first, then item 23 second, and item 17 third, I want the listbox on the right to display:

Item 2
Item 23
Item 17

Now while I can get the user to click on Item 2, then Add (in which the compiler loops through the list items and puts the selected one in the second list), then item 23, then Add, and so on, I want to automate the process a little more. I know the "Selected" property of a listbox is an array of booleans.

I came across this, but its in jQuery, and I don't know the first thing about it:

Thoughts? Is there some way by which I can get the compiler to remember the order of selection?

1

1 Answers

2
votes

You could use a collection and keep track of the indices selected yourself.

Dim selectedIndices As New Collection

Then on the listbox selected or deselected use the Add() or Remove() function

selectedIndices.Add(index)
selectedIndices.Remove(index)

depending on the state of the item in the left list box. Then instead of using the selected property of the listbox, loop through your collection and add them in that order.