Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

diya:

This is one way I have used in the past to handle your requirement. Hope this helps.

 

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;
}

 

 

 

 

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...