Database one column to ListBox?
Hi,
From my database I have managed to fire a query so select just one column of the name of the details I want.
It shows up fine in the data grid but I want to use ListBox instead of DataGrid.
How can I achieve this?
Here is my code:
http://i.imgur.com/m42MB7g.png
This is the result:
http://i.imgur.com/lprTdGy.png
Please let me know what I can do.
Re: Database one column to ListBox?
Start by posting code as text wrapped in code tags...
You need to set the DisplayMember of the list box to the data table column name.
Code:
ListBox1.DisplayMember="CName"
I can't remember whether the DisplayMember should be set before or after the data source is set, but I do believe it matters.
Re: Database one column to ListBox?
DisplayMember and ValueMember both need to be set BEFORE the DataSource ... Doesn't matter which order Display/Value member gets set, they just need to be set before the datasource.
-tg
Re: Database one column to ListBox?
Quote:
Originally Posted by
kebo
Start by posting code as text wrapped in code tags...
You need to set the DisplayMember of the list box to the data table column name.
Code:
ListBox1.DisplayMember="CName"
I can't remember whether the DisplayMember should be set before or after the data source is set, but I do believe it matters.
Quote:
Originally Posted by
techgnome
DisplayMember and ValueMember both need to be set BEFORE the DataSource ... Doesn't matter which order Display/Value member gets set, they just need to be set before the datasource.
-tg
Thanks guys, that worked! Thank you so much! +rep. :)