Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
We have both DisplayMember and ValueMember properties of a listbox filled with 2 field of a table. On selecting any element in listbox, we want to get ValueMember property's value to retrieve associated record from the table.

We used ListBox1.SelectedValue for this purpose which returns "System.Data.DataRowView".

listBox2.DataSource = MainDataSet.Tables["Members"];
                listBox2.DisplayMember = "MemberName";
                listBox2.ValueMember = "MemCode";
                MessageBox.Show(listBox2.SelectedValue.ToString());
Posted

1 solution

You will need to create your own class to get the SelectedValue.
Notice how the listbox datasource is set to the USState class in this msdn example[^].
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900