diya Posted March 5, 2005 Posted March 5, 2005 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. Quote
RobEmDee Posted March 6, 2005 Posted March 6, 2005 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.