简体   繁体   English

如何在运行时设置过滤器? 用于C#,Winforms,DevExpress中的gridview

[英]How to set Filter in run time ? for gridview in C#, Winforms, DevExpress

I attach new DataSource and DataSet on Run Time. 我在运行时附加了新的DataSource和DataSet。 I set the filter also in the Run Time but it shows error 我也在运行时中设置了过滤器,但显示错误

Cannot find column [invoice_number] 找不到列[发票编号]

my code : 我的代码:

// Create a data adapter. 
OleDbDataAdapter adapter = 
    new OleDbDataAdapter("SELECT * FROM gridview", connection);

// Create and fill a dataset. 
DataSet sourceDataSet = new DataSet();
adapter.Fill(sourceDataSet);

// Specify the data source for the grid control. 
gridControl1.DataSource = sourceDataSet.Tables[0];

// error show in this line
invoiceBindingSource.Filter = 
    string.Format("invoice_number = '{0}'", textEdit5.Text);

but my OrionSystem Access Database has the Column "invoice_number" in the table gridview. 但是我的OrionSystem Access数据库在表格gridview中有“ invoice_number”列。 What is my error ? 我的错误是什么?

或者,您始终可以设置GridView.ActiveFilterString属性。

You're setting the filter on the bindingsource, but you set the datasource directly on the grid control. 您在绑定源上设置过滤器,但直接在网格控件上设置数据源。

You must set the datasource on the bindingsource, and then set the grid's datasource to the bindingsource: 您必须在绑定源上设置数据源,然后将网格的数据源设置为绑定源:

// Create a data adapter. 
OleDbDataAdapter adapter = 
    new OleDbDataAdapter("SELECT * FROM gridview", connection);

// Create and fill a dataset. 
DataSet sourceDataSet = new DataSet();
adapter.Fill(sourceDataSet);

// Specify the data source for the bindingsource. 
invoiceBindingSource.DataSource = sourceDataSet.Tables[0];

// Specify the data source for the grid control. 
gridControl1.DataSource = invoiceBindingSource;

// error show in this line
invoiceBindingSource.Filter = 
    string.Format("invoice_number = '{0}'", textEdit5.Text);

Cheers 干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在EditValue中设置GridView的筛选器已更改? Winforms Devexpress - How to set filter for GridView in EditValue changed ? Winforms Devexpress 如何从Access数据库获取值并在C#winforms Devexpress中的Gridview中进行设置? - How to get the values from Access Database and set in Gridview in C# winforms Devexpress? 如何在Winforms应用程序上使用C#代码进行databind到devexpress gridview? - How to do databind to devexpress gridview using C# code on winforms app? 如何使用 Winforms 中的 C# 代码在 DevExpress Gridview 中添加新行? - How to add new row in DevExpress Gridview using C# code in Winforms? c# 如何使用 DevExpress(Gridview) 向 WinForms 添加未绑定的复选框列? - c# How to add unbound check box column to WinForms with DevExpress(Gridview)? 如何将单击事件设置为行中的所有单元格? Gridview Winforms Devexpress - How to set click Event to all cells in a Row ? Gridview Winforms Devexpress GridView Devexpress C# - gridview Devexpress c# 包含过滤器搜索不适用于devexpress gridview c# - Contains filter search doesn't work for devexpress gridview c# 不区分大小写的重音 devexpress 过滤器 gridview c# - Case insensitive accent devexpress filter gridview c# 在c#中的devexpress gridview中的ListBox - ListBox in devexpress gridview in c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM