簡體   English   中英

根據C#中另一列的當前行過濾datagridview列

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

我有一個datagridview,它正在填充來自不同表的列。 我想根據當前行的另一列來過濾列。 我嘗試使用datagridview的單元格enter事件,然后通過過濾當前行的列上的綁定源來過濾該列。

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值無效。

任何建議

是item_id字段是字符串類型還是數字類型。如果是字符串類型,則必須使用單整數。

好吧,你可以這樣使用

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM