How do I move the data bound contents of one listbox to another

salja

Newcomer
Joined
Mar 23, 2003
Messages
1
I have two listboxes side by side. The listbox on the left is bound to a table, and shows Sql selected data from that table. I need to Add selected items from this listbox to the listbox on the right which is not bound to anything. The Listbox on the left has the following properties:

DisplayMember= Text field giving a display name from the table
ValueMember=UniqueID for item in the table

When I use the following:

RightSideListBox.Items.Add(LeftSideListBox.SelectedValue)

all I get is the Valuemember appearing in the right hand listbox. What I need is the DisplayMember showing in the right hand listbox, and some way of also recording the Valuemember, so I can retrieve data from the same table later, based on the UniqueID it returns for the originating table.

I tried using :

RightSideListBox.Items.Add(LeftSideListBox.SelectedItem)

but while that appears to add the datarow object to the right hand listbox, it displays 'System.Data.DataRowView' in the listbox control. Again, what I need is to see the same DisplayMember for the selected item in the left side listbox displayed in the right side listbox, and have some way of retrieving the ValueMember for later use.

Any help is greatfully appreciated!

Regards,

James
 
you can use the Dataset Tables to get the selected item...
Visual Basic:
ds.Tables(0).Rows(LeftSideListBox.SelectedIndex).Item(1)
'Tables(0)... is the first table (you can use the name instead
'Item(0)... is the ColumnIndex, you probably have 2 columns in this case.
 
Back
Top