[英]Set a value in a Datagridviewcomboboxcell in datagridview when i click a cell in other datagridview in the same winForm in C#
我在同一個 WinForm 中有兩個 Datagridview,在一個中我有一個 Datagridviewcomboboxcell 類型的列,它們從列表中分配值。 當我 select 在第二個 datagridview 的單元格中設置值時,我希望能夠在 combobox 單元格中設置當前值。 combobox 的當前值將等於所選值。
我非常感謝您的幫助。
我假設兩個 DataGridView 控件的行相等,然后您可以在CellValueChanged
事件上設置單元格值:
private void dataGridView2_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Rows[e.RowIndex].Cells["ColumnName"].Value =
dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
}
當索引超出范圍時,有必要添加一些保護以避免異常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.