public static void AddFullSelect() { System.Windows.Forms.CheckBox ckBox = new System.Windows.Forms.CheckBox(); ckBox.Text = ""; ckBox.Checked = false; System.Drawing.Rectangle rect = dgv.GetCellDisplayRectangle(0, -1, true); ckBox.Size = new System.Drawing.Size(13, 13); ckBox.Location = new Point(rect.Location.X + dgv.Columns[0].Width / 2 - 13 / 2 - 1, rect.Location.Y + 7); //ckBox.Location.Offset(-40, rect.Location.Y); ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged); dgv.Controls.Add(ckBox); }
public static void AddFullSelect() { if (dgv.Rows.Count < 1) { return; } System.Windows.Forms.CheckBox ckBox = new System.Windows.Forms.CheckBox(); ckBox.Text = "全选"; ckBox.Checked = true; System.Drawing.Rectangle rect = dgv.GetCellDisplayRectangle(0, -1, true); ckBox.Size = new System.Drawing.Size(dgv.Columns[0].Width, 18); ckBox.Location = rect.Location; ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged); dgv.Controls.Add(ckBox); }