gpt4 book ai didi

c# - DataGridView ComboBox EditingControlShowing 事件

转载 作者:行者123 更新时间:2023-11-30 14:16:54 26 4
gpt4 key购买 nike

我有一个基本的 WinForms 应用程序,上面有 d DataGridView(名为 dgvHardware)控件,绑定(bind)到这个控件的是这段代码:

    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 选择更改行中的其他单元格。第二个函数中的结果返回正确的值,这是值得的。

如果不清楚或者您需要任何其他信息,请告诉我。

谢谢,
安德鲁

最佳答案

使用 DataGridView.CurrentCell Property像这样:

int row = dgvHardware.CurrentCell.RowIndex;

关于c# - DataGridView ComboBox EditingControlShowing 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6702729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com