I have a datagrid开发者_如何学运维view 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
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());
}
}
精彩评论