我有d的DataGridView(名爲dgvHardware)上的控制權,勢必這種控制基本WinForms應用程序是這樣的代碼:DataGridView的組合框EditingControlShowing事件
private void dgvHardware_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is ComboBox)
{
((ComboBox)e.Control).SelectionChangeCommitted -= new EventHandler(cboDgvHardware_SelectionChanged);
((ComboBox)e.Control).SelectionChangeCommitted += new EventHandler(cboDgvHardware_SelectionChanged);
}
}
private void cboDgvHardware_SelectionChanged(object sender, EventArgs e)
{
// string result is the selected text of the combo box
// int row is the row index that the selected combo box lives
string result = ((ComboBox)sender).SelectedItem.ToString();
// int row = ????
}
長話短說,我需要能夠以確定事件正在觸發的行,以便根據ComboBox選擇更改行中的其他單元格。 結果在第二個函數中返回正確的值,它是值得的。
讓我知道,如果這不清楚,或者如果你需要任何額外的信息。
感謝,
安德魯
賓果!這是99%正確的,DataGridView被命名爲dgvHardware,所以完全正確的行是: 'int row = dgvHardware.CurrentCell.RowIndex;' – Fuginator
@Fuginator Opps,複製並粘貼錯誤。更正! –