【问题标题】:How to set Filter in run time ? for gridview in C#, Winforms, DevExpress如何在运行时设置过滤器?用于 C#、Winforms、DevExpress 中的 gridview
【发布时间】:2013-11-09 05:44:17
【问题描述】:

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

找不到列 [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”。我的错误是什么?

【问题讨论】:

  • 您是否为 invoiceBindingSource 设置了数据?

标签: c# winforms gridview devexpress


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    必须在bindingsource上设置datasource,然后将grid的datasource设置为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);
    

    干杯

    【讨论】:

      猜你喜欢
      • 2014-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多