views:

220

answers:

1

I have a datagridview that is populating columns from different table. I want to filter the column based on another column of the current row. I tried to use the cell enter event of the datagridview and then filtered the column by filtering the binding source on the column of the current row.

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

This is how I am filtering the "problem " binding source on the cell enter event of the datagridview . It is working fine but I am getting an error- being: System.ArgumentException: DataGridViewComboBoxCell value is not valid.

Any suggestion

A: 

Is item_id field is string type or number type.If it is a string type you have to put in single cote.

Well you can use like this

 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());
        }
    }
Wonde
item_id is an integer .
It does not work as well