How do I bind the result of DataTable.Select() to a ListBox control?

前提是你 提交于 2019-12-03 06:42:06

Use a DataView instead.

ListBox.DataSource = new DataView(DataSet.Tables("table_name"), "some_criteria = match", "name", DataViewRowState.CurrentRows);
ListBox.DisplayMember = "name"

Josh has it right with the DataView. If you need a very large hammer, you can take the array of rows from any DataTable.Select("...") and do a merge into a different DataSet.


 DataSet copy = new DataSet();
 copy.Merge(myDataTable.Select("Foo='Bar'"));
 // copy.Tables[0] has a clone

That approach for what you're trying to do is most probably overkill but there are instances when you may need to get a datatable out of an array of rows where it's helpful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!