I have the following code:
ListBox.DataSource = DataSet.Tables("table_name").Select("some_criteria = match")
ListBox.DisplayMember = "name"
The DataTable.Select()
method returns an array of System.Data.DataRow
objects.
No matter what I specify in the ListBox.DisplayMember
property, all I see is the ListBox with the correct number of items all showing as System.Data.DataRow
instead of the value I want which is in the "name"
column!
Is it possible to bind to the resulting array from DataTable.Select()
, instead of looping through it and adding each one to the ListBox
?
(I've no problem with looping, but doesn't seem an elegant ending!)
Use a DataView instead.
ListBox.DataSource = new DataView(DataSet.Tables("table_name"), "some_criteria = match", "name", DataViewRowState.CurrentRows);
ListBox.DisplayMember = "name"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With