我正在通过WinForms应用程序中的DataGridView显示数据库记录。另外,我有一个textview,组合框和datetimepicker。我如何排序datagridview只显示等于textview或combobox或datetimepicker的记录?

最佳答案

描述

您需要在例如BindingSourceDataSet之间的DataGridView

使用BindingSource,您可以过滤数据源,因为BindingSource具有.Filter属性。

如果更改过滤器,它也会过滤您的DataGridView


  BindingSource.Filter获取或设置用于过滤查看哪些行的表达式。


样品

从工具箱添加BindingSource,这只是一个示例

BindingSource myBindingSource = new BindingSource();
myBindingSource.DataSource = myDataTable;
myDataGridView.DataSource = myBindingSource;

myBindingSource.Filter =// your filter


更多信息


MSDN - How to: Bind Data to the Windows Forms DataGridView Control
MSDN - BindingSource Class
Exploring Secrets of BindingSource Filters - Learn how to give users fast DataGridView filtering power so they can hone in on the data they're truly interested in.

关于c# - DataGridView Windows窗体,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9008131/

10-11 20:34