Newer
Older
IRIS_COLLECT_GA / IOM_cs / insertForm / dtGridView / CheckBoxClass.cs
yangqianqian on 1 Jun 2021 1 KB first commit
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace IOM_cs.insertForm.dtGridView
{
    public class CheckBoxClass
    {
        public static DataGridView dgv;

        public static void AddFullSelect()
        {
            if (dgv.Rows.Count >= 1)
            {
                CheckBox ckBox = new CheckBox();
                ckBox.Text = "";
                ckBox.Checked = false;
                Rectangle rect =
                dgv.GetCellDisplayRectangle(0, -1, true);
                ckBox.Size = new Size(dgv.Columns[0].Width, 18);
                ckBox.Location = new Point(rect.Location.X + 2, rect.Location.Y + 2);
                ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged);
                dgv.Controls.Add(ckBox);
            }
        }

        static void ckBox_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                dgv.Rows[i].Cells[0].Value = ((CheckBox)sender).Checked;
            }
            dgv.EndEdit();
        }

    }
}