c# – DataGridView ComboBox EditingControlShowing事件

c# – DataGridView ComboBox EditingControlShowing事件,第1张

概述我有一个基本的WinForms应用程序与d DataGridView(名为dgvHardware)控件,绑定到此控件是这段代码: private void dgvHardware_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (e.Control 我有一个基本的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选择更改行中的其他单元格.第二个函数的结果返回正确的值,这是值得的.

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

谢谢,
安德鲁

解决方法 像这样使用 DataGridView.CurrentCell Property:

int row = dgvHarDWare.CurrentCell.RowIndex;
总结

以上是内存溢出为你收集整理的c# – DataGridView ComboBox EditingControlShowing事件全部内容,希望文章能够帮你解决c# – DataGridView ComboBox EditingControlShowing事件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1217028.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存