/// <summary> ///add a full selection to DataGridView/// </summary> Public classAddcheckboxtodatagridview { Public StaticSystem.Windows.Forms.DataGridView DGV; Public Static voidAddfullselect () {if(DGV. Rows.Count <1) { return; } System.Windows.Forms.CheckBox Ckbox=NewSystem.Windows.Forms.CheckBox (); Ckbox.text="Select All"; Ckbox.checked=true; System.Drawing.Rectangle rect=DGV. Getcelldisplayrectangle (0, -1,true); Ckbox.size=NewSystem.Drawing.Size (DGV. columns[0]. Width, -); Ckbox.location=rect. Location; Ckbox.checkedchanged+=NewEventHandler (ckbox_checkedchanged); DGV. Controls.Add (Ckbox); } Static voidCkbox_checkedchanged (Objectsender, EventArgs e) { for(inti =0; I < DGV. Rows.Count; i++) {DGV. Rows[i]. cells[0]. Value =((System.Windows.Forms.CheckBox) sender). Checked; } DGV. EndEdit (); } }
Calling methods
ADDCHECKBOXTODATAGRIDVIEW.DGV = Dgvks_ry; Addcheckboxtodatagridview.addfullselect ();
DataGridView Adding a Batch selection box to a table header