2010-03-20 86 views
2

我有一个datagridview从不同的表中填充列。我想根据当前行的另一列过滤列。我尝试使用datagridview的单元格输入事件,然后通过过滤当前行的列上的绑定源来过滤列。基于C#中另一列的当前行过滤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值无效。

任何建议

回答

0

是ITEM_ID字段是字符串类型或数量type.If它是你必须把 单科特字符串类型。

那么你可以使用这样

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

ITEM_ID是一个整数。 – user286546 2010-03-22 14:56:02

+0

它不起作用 – user286546 2010-03-26 21:31:18