简体   繁体   中英

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

I attach new DataSource and DataSet on Run Time. 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM