Pass Listitem between Listboxes

G

Guest

I have two listboxes. The first listbox is prepopulated with the selections
that the user has. The "Value" of the items is NOT the same as the "Text".
The user can select an item (or items) from one listbox and move it to the
other listbox. The code for it is:

Dim x, deleted As Integer

For x = 0 To lboxFrom.Items.Count - 1
If lboxFrom.Items.Item(x - deleted).Selected Then
lboxTo.Items.Add(lboxFrom.Items.Item(x - deleted))
lboxFrom.Items.Remove(lboxFrom.Items.Item(x - deleted))
deleted += 1
End If
Next

I have also tried:

Dim x, deleted As Integer

For x = 0 To lboxFrom.Items.Count - 1
If lboxFrom.Items.Item(x - deleted).Selected Then
Dim newItem As New ListItem()
newItem.Text = lboxFrom.Items.Item(x - deleted).Text
newItem.Value = lboxFrom.Items.Item(x - deleted).Value
lboxTo.Items.Add(newItem)
lboxFrom.Items.Remove(lboxFrom.Items.Item(x - deleted))
deleted += 1
End If
Next

The item that passes to the second listbox should have value of the first
listbox item and also the text of the first listbox item. My problem is that
the value and the text of the item placed in the second listbox end up the
same and equal the text of the item in the first listbox. Why is it doing
this and what can I do to get the value for the item from the first listbox
to pass as the value for the item in the second listbox?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top