簡體   English   中英

如何在運行時設置過濾器? 用於C#,Winforms,DevExpress中的gridview

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

我在運行時附加了新的DataSource和DataSet。 我也在運行時中設置了過濾器,但顯示錯誤

找不到列[發票編號]

我的代碼:

// 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”列。 我的錯誤是什么?

或者,您始終可以設置GridView.ActiveFilterString屬性。

您在綁定源上設置過濾器,但直接在網格控件上設置數據源。

您必須在綁定源上設置數據源,然后將網格的數據源設置為綁定源:

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

干杯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM