如何创建事件处理程序DataGridViewComboBoxColumn在数据网格视图在winform [英] How to create Event Handler for DataGridViewComboBoxColumn in a Data Grid View in Winform

查看:113
本文介绍了如何创建事件处理程序DataGridViewComboBoxColumn在数据网格视图在winform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据网格视图DataGridViewComboBoxColumn。我附上一个列表作为数据源。现在我需要消防基础上,combobox..How的选定索引我可以去aboout做一个事件?由于提前

I have a DataGridViewComboBoxColumn in a data grid view. I have attached a list as a data source . Now i need to fire an event based on the selected index of the combobox..How can I go aboout doing it ? Thanks in Advance

推荐答案

鉴于的SelectedIndex 属性属于编辑控制(这是唯一的活动时, DataGridView的是在编辑模式下),您可以附加一个事件处理程序 EditingControlShowing 像所以:

Given that the SelectedIndex property belongs to the editing control (which is only active when the DataGridView is in edit mode), you could attach an event handler to EditingControlShowing like so:

void dataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) {
    if (e.Control is ComboBox) {
        // remove handler first to avoid attaching twice
        ((ComboBox)e.Control).SelectedIndexChanged -= MyEventHandler;
        ((ComboBox)e.Control).SelectedIndexChanged += MyEventHandler;
    }
}

请注意,控制的实际类型是 DataGridViewComboBoxEditingControl ,它扩展了组合框。你只需要从基类的功能,再加上它的打字比较少。

Note that the actual type of the control is DataGridViewComboBoxEditingControl, which extends ComboBox. You only need the functionality from the base class, plus it's less to type.

这篇关于如何创建事件处理程序DataGridViewComboBoxColumn在数据网格视图在winform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆