winfrom表格DataGridView下拉框DataGridViewComboBoxColumn选择事件

本文介绍了如何在Windows窗体应用中处理DataGridView的下拉框选择事件。通过设置DataGridView的EditMode属性,添加EditingControlShowing和CellEnter事件,实现了单击显示下拉列表,并在ComboBox的SelectedIndexChanged事件中更新相关单元格的数据。同时,详细展示了数据绑定和下拉框内容设置的过程。
摘要由CSDN通过智能技术生成


1、列的ColumnType选择:DataGridViewComboBoxColumn;


2、表格的属性EditMode设置为EditOnEnter;


3、表格添加EditingControlShowing事件;


4、实现单击一次显示下拉列表框,添加CellEnter事件;


bool isBind = false;//是否已经绑定事件
        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
           //判断要处理的DataGridViewComboBoxColumn名称,若符合条件,编辑控件被强制转换为ComboBox以处理,添加SelectedIndexChanged事件
            if (this.dataGridView1.CurrentCell.OwningColumn.Name == "Good" && dataGridView1.CurrentCell.RowIndex != -1)
            {
                System.Windows.Forms.ComboBox cb = (System.Windows.Forms.ComboBox)e.Control;


                if (!isBind)
                {
                    cb

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值