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

时间:2013-11-09 05:44:18

标签: c# winforms gridview devexpress

我在运行时附加了新的DataSource和DataSet。我也在运行时设置过滤器,但它显示错误

  

找不到列[invoice_number]

我的代码:

// 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);

但我的OrionSystem Access数据库在表gridview中有列“invoice_number”。我的错误是什么?

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

您正在绑定源上设置过滤器,但您可以直接在网格控件上设置数据源。

您必须在bindingsource上设置数据源,然后将网格的数据源设置为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);

干杯