我有一个数据 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/