DataGridView ComboBox EditingControlShowing events
本文关键字:events EditingControlShowing ComboBox DataGridView | 更新日期: 2023-09-27 18:02:14
我有一个基本的WinForms应用程序d DataGridView(命名为dgvHardware)控制它,绑定到这个控件是这个代码:
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选择更改行中的其他单元格。第二个函数中的结果返回正确的值。
如果我不清楚,或者如果你需要任何额外的信息,请告诉我。
谢谢,
安德鲁。
使用DataGridViewCurrentCell属性如下:
int row = dgvHardware.CurrentCell.RowIndex;
您可能对dgvHardware.CurrentRow
感兴趣,它将使您可以访问整个行,并且您可以使用dgvHardware.CurrentRow.Cells[index or columnName]
导航到不同的列并更改其他单元格值。