get listbox.valuemember

diya

Newcomer
Joined
Oct 27, 2003
Messages
3
I have a 2 listboxes :- listbox1,listbox2 in a form that is databound

I've set the Listbox Data Bindings via the following code:


listbox1.DataSource = mydatatable
listbox1.DisplayMember = "text"
listbox1.ValueMember = "value"

I have set the selection mode to multipleextended.

Now when i loop thro the selected items i want to get the value of
each of the selected item and populate Listbox 2 with the selected item and its value.

How do i got about doing this.

I know that i can get the all the selected items using the listbox1.selectedindices.
But my problem is how do i get the value of the each selected Item.

Can it be done with the valuemember property ? if so how?

Thanks in adv for the help.
 
diya:
This is one way I have used in the past to handle your requirement. Hope this helps.

Code:
public ArrayList SelectedValues()
{
      ArrayList selValues = new ArrayList();
      DataRow row;
      
      for(int count = 0; count < this.listBox1.SelectedItems.Count; count++)
      {
	row = ((DataRowView) this.listBox1.SelectedItems[count]).Row;
	selValues.Add(row[this.listBox1.ValueMember]);
	row = null;
      }

      return selValues;
}




diya said:
I have a 2 listboxes :- listbox1,listbox2 in a form that is databound

I've set the Listbox Data Bindings via the following code:


listbox1.DataSource = mydatatable
listbox1.DisplayMember = "text"
listbox1.ValueMember = "value"

I have set the selection mode to multipleextended.

Now when i loop thro the selected items i want to get the value of
each of the selected item and populate Listbox 2 with the selected item and its value.

How do i got about doing this.

I know that i can get the all the selected items using the listbox1.selectedindices.
But my problem is how do i get the value of the each selected Item.

Can it be done with the valuemember property ? if so how?

Thanks in adv for the help.
 
Back
Top