【问题标题】:DataTable & Bindingsource unable to castDataTable & Bindingsource 无法转换
【发布时间】:2015-10-20 04:42:40
【问题描述】:

我正在尝试使用数据表在我的 datagridview 中创建一个多条件过滤器。唯一的问题是将 gridview 转换为表格,并尝试在此处和 MSDN 论坛找到更多答案。它仍然无法正常工作,现在我被卡住了。 这是我的完整方法:

  public void updateText(string txt, string txt2, string txt3)         
  {
        myform = null;
        var bs = (BindingSource)dataGridView1.DataSource;
        var table = (DataTable)bs.DataSource;
        table.Select("Azonosito Like '%" + txt + "%' AND Név Like '%" + txt2 + "%'");
        label4.Text = "Lefutott";  //just for debugging reasons to see if it runs
        dataGridView1.DataSource = table;
  }

Azonosisto an Név 是 cloumn 标题。 txt3目前没有使用,以后可能会用到,所有的过滤文本都来自另一个表单使用这个方法。

【问题讨论】:

    标签: c# datagridview datatable filtering bindingsource


    【解决方案1】:

    您需要调用 DataBind 方法。 我认为如果你最后添加这一行(在你分配数据源之后)它应该可以工作。

    dataGridView1.DataBind();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-30
      • 1970-01-01
      • 1970-01-01
      • 2011-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多