如何将DataTable.Select()的结果绑定到ListBox控件? [英] How do I bind the result of DataTable.Select() to a ListBox control?
问题描述
我有以下代码:
ListBox.DataSource = DataSet.Tables(table_name)。选择(some_criteria = match)
ListBox.DisplayMember =name
DataTable.Select()
方法返回一个数组 System.Data.DataRow
对象。
无论我在 ListBox.DisplayMember
属性,所有我看到的是正确数量的列表框,全部显示为 System.Data.DataRow
而不是我想要的值在name
列!
是否可以绑定到来自 DataTable.Select()
的结果数组,而不是遍历它,并将每个添加到 ListBox
?
使用 DataView 。
ListBox.DataSource = new DataView(DataSet.Tables(table_name),some_criteria = match,name,DataViewRowState.CurrentRows);
ListBox.DisplayMember =name
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"
这篇关于如何将DataTable.Select()的结果绑定到ListBox控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!