c# – DataGridView ComboBox EditingControlShowing事件
发布时间:2020-12-16 01:45:36 所属栏目:百科 来源:网络整理
导读:我有一个基本的WinForms应用程序与d DataGridView(名为dgvHardware)控件,绑定到此控件是这段代码: private void dgvHardware_EditingControlShowing(object sender,DataGridViewEditingControlShowingEventArgs e) { if (e.Control is ComboBox) { ((ComboB
我有一个基本的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; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |