开发者

Filter the datagridview column based on the current row of another column in C#

开发者 https://www.devze.com 2022-12-23 19:55 出处:网络
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 t

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号