[C#]给DataGridView里的ComboBoxCol添加SelectIndexChange事件

        const string DGVCBCellType = "System.Windows.Forms.DataGridViewComboBoxCell";
        const string DGVTBCellType = "System.Windows.Forms.DataGridViewTextBoxCell";

       public CDynIngDGV()  //构造函数
        {
            this.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(CDynIngDGV_EditingControlShowing);
            this.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
        }

        void CDynIngDGV_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {

            switch (e.Control.GetType().ToString())
            {
                case DGVCBCellType:
                    ((ComboBox)e.Control).SelectedValueChanged += new EventHandler(CDynIngDGV_SelectedValueChanged);
                    break;

                case DGVTBCellType:

                    break;
            }
           
        }

        void CDynIngDGV_SelectedValueChanged(object sender, EventArgs e)
        {
            switch (sender.GetType().ToString())
            {
                case DGVCBCellType:
                    MessageBox.Show(((ComboBox)sender).SelectedValue.ToString());
                    break;

                case DGVTBCellType:

                    break;
            }
           
        }

原文地址:https://www.cnblogs.com/boneking/p/1333795.html