zoukankan      html  css  js  c++  java
  • C# winform datagridview 内嵌控件值改变后立即触发事件,而不需要离开该单元格时才触发,此时需要用到dgv_CurrentCellDirtyStateChanged事件

    以下是参考代码

            //datagridview内嵌控件值修改事件
            private void dgv_CurrentCellDirtyStateChanged(object sender, EventArgs e)
            {
                if (dgv.IsCurrentCellDirty)
                {
                    dgv.CurrentCellDirtyStateChanged -= dgv_CurrentCellDirtyStateChanged;
                    dgv.CommitEdit(DataGridViewDataErrorContexts.Commit);
                    dgv.CurrentCellDirtyStateChanged += dgv_CurrentCellDirtyStateChanged;
                    c = dgv.CurrentCellAddress.X;
                    r = dgv.CurrentCellAddress.Y;
                    DataGridViewComboBoxCell cbbCellContorlType = (DataGridViewComboBoxCell)dgv.Rows[r].Cells["innerContorlType"];
                    DataGridViewComboBoxCell cbbCellDefaultValue = (DataGridViewComboBoxCell)dgv.Rows[r].Cells["defaulValue"];
                    DataGridViewCheckBoxCell cbCell = (DataGridViewCheckBoxCell)dgv.Rows[r].Cells["isEdit"];
                    switch (dgv.Columns[c].Name)
                    {
                        case "isEdit":
                            #region 修改是否可编辑
                            if (!bool.Parse(cbCell.EditedFormattedValue.ToString()))
                            {
                                cbbCellContorlType.Value = "";
                                cbbCellContorlType.ReadOnly = true;
                                cbbCellDefaultValue.Value = "";
                                cbbCellDefaultValue.ReadOnly = true;
                            }
                            else
                            {
                                cbbCellContorlType.ReadOnly = false;
                                cbbCellContorlType.Value = "TextBox";
                                cbbCellDefaultValue.ReadOnly = false;
                                cbbCellDefaultValue.Value = "";
                            }
                            #endregion 修改是否可编辑
                            break;
                        case "defaulValue":
                            #region 修改控件类型
                            string ctrlType = cbbCellContorlType.Value.ToString();
                            string ctrlItem = cbbCellDefaultValue.Value.ToString();
                            if (ctrlItem == "增加值…")
                            {
                                switch (ctrlType)
                                {
                                    case "DropDownList":
                                        #region DropDownList
                                        frmddl.Show();
                                        frmddl.tbDDL.Clear();
                                        foreach (string item in cbbCellDefaultValue.Items)
                                        {
                                            int n = cbbCellDefaultValue.Items.IndexOf(item);
                                            if (n > 1)
                                            {
                                                if (n == 2)
                                                    frmddl.tbDDL.Text += item;
                                                else
                                                    frmddl.tbDDL.Text += "
    " + item;
                                            }
                                        }
                                        frmddl.btnConfirm.Click += btnConfirm_Click;
                                        #endregion DropDownList
                                        break;
                                    case "ImageButton":
                                        #region ImageButton
                                        frmbtn.Show();
                                        frmbtn.btnConfirmImage.Click += btnConfirmImage_Click;
                                        #endregion ImageButton
                                        break;
                                }
                            }
                            #endregion 修改控件类型
                            break;
                        default:
                            break;
                    }
                }
            }
  • 相关阅读:
    Python 进程管理工具 Supervisor 使用教程
    Python cx_Oracle 安装小记
    使用 IIS 过程中遇到的一些问题
    http请求的post提交数据的四种格式form-data,row,binary,urlencode
    sqlmap 笔记
    数据库服务器及命令行相关操作
    SDL应用软件安全研发周期
    ldap目录访问协议
    计算机行业证书解释
    gunicorn Python部署应用
  • 原文地址:https://www.cnblogs.com/swtool/p/3734766.html
Copyright © 2011-2022 走看看