20230425001 - DataGridView绑定了数据之后, 再添加CheckBox列的解决方案

 

 

              if (dgv_M.Columns[0].Name != "select")
             {
                    DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
                    checkBoxColumn.Name = "select";
                    checkBoxColumn.HeaderText = "选择";
                    dgv_M.Columns.Insert(0, checkBoxColumn);
                    dgv_M.ReadOnly = false;
                    dgv_M.Columns["ID"].ReadOnly = true;
                    dgv_M.Columns["单号"].ReadOnly = true;
            }

 

            if (dgv_M != null && dgv_M.Rows.Count > 0)
            {
                DialogResult result = MessageBox.Show("删除后不可恢复,\r\n确定需要删除吗?", "删除确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    string str_Num = "";
                    for (int i2 = 0; i2 < dgv_M.Rows.Count; i2++)
                    {
                        string flag = dgv_M.Rows[i2].Cells["select"].EditedFormattedValue.ToString();
                        if (flag == "True")
                        {
                        }
                    }   

                }
            }

posted @ 2023-04-25 09:15  追逐苦痛  阅读(68)  评论(0编辑  收藏  举报