Why I get "System.Data.DataRowView" instead of real values in my Listbox?

I always have to deal with this problem, even if I set the DisplayMember and ValueMembers of the List Box.

Your current code is correct and should work, if you need access to the current selected item value of any column of your dTable you can get them doing this:

DataRowView drv = (DataRowView)lstNames.SelectedItem;
String valueOfItem = drv["NameAndScore"].ToString();

What I like about getting the entire DataRowView is that if you have more columns you can still access their values and do whatever you need with them.


The following code should work:

DataSet dSet = new DataSet();
dAdapter.Fill(dSet);

lstNames.DisplayMember = "NameAndScore";
lstNames.ValueMember = "NameAndScore";
lstNames.DataSource = dSet.Tables[0];

If it does not work, please update your question and provide us with some information about the columns and values that are actually returned in dSet.Tables[0].


Set your lstNames.DisplayMember and lstNames.ValueMember fields.

Gets or sets the property to display for this ListControl.


Gets or sets the path of the property to use as the actual value for the items in the ListControl.

This should solve your problem..

Tags:

C#

Mysql

Winforms