c# - C#中根据另一列的当前行过滤datagridview列

标签 c# events datagridview

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

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

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

任何建议

最佳答案

item_id字段是string类型还是number类型,如果是string类型就得填 单人床。

你可以这样使用

 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());
        }
    }

关于c# - C#中根据另一列的当前行过滤datagridview列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2483907/

相关文章:

c# - ServiceStack ApiKeyAuthProvider 在每个请求上触发 6 个选择语句

c# - 舍入 WPF 绑定(bind)中的值

wpf - 如何重构 WPF 中的事件?

c# - Datagridview 格式列问题

c# - 如何在 Winform 应用程序中获取 datagridview 特定单元格的值

c# - ASP.NET 5 : Access-Control-Allow-Origin in response

c# - 实现 XML 文件转换器时进行单元测试

iphone - 如何从 iphone 应用程序将事件添加到 Google 日历?

ruby - 如何在 Ruby 中执行事件?

c# - 如何让我的 DataGridView 的 CellPainting 事件与部分显示的单元格一起使用?