【问题标题】:Filter the datagridview column based on the current row of another column in C#C#中根据另一列的当前行过滤datagridview列
【发布时间】:2011-01-29 20:18:54
【问题描述】:

我有一个 datagridview 正在填充来自不同表的列。我想根据当前行的另一列过滤该列。我尝试使用datagridview的单元格输入事件,然后通过过滤当前行列上的绑定源来过滤列。

private void lINKDataGridView_CellEnter(object sender, DataGridViewCellEventArgs e)
{
    this.pROBLEMBindingSource.Filter = "item_id = " + this.lINKDataGridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumn4.Index].Value + "";
}

这就是我在 datagridview 的单元格输入事件上过滤“问题”绑定源的方式。它工作正常,但出现错误:System.ArgumentException:DataGridViewComboBoxCell 值无效。

任何建议

【问题讨论】:

    标签: c# events datagridview


    【解决方案1】:

    item_id字段是字符串类型还是数字类型。如果是字符串类型你必须输入 单包。

    你可以这样使用

     private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
     {
      // [ Item_id column ] Make sure to use the item_id column index
      if (e.ColumnIndex == 5) 
            {
               userBindingSource.Filter = "Item_Id = " + Convert.ToInt64(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2021-08-01
      • 2016-11-22
      • 2020-12-08
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多