public HeaderCheckBoxHandler(DataGridViewCheckBoxColumn checkBoxColumn, DataGridView grid) { this.checkBoxColumn = checkBoxColumn; this.grid = grid; headerCheckBox = new UnselectableCheckbox { Size = new Size(15, 15), TabStop = false, }; grid.Controls.Add(headerCheckBox); headerCheckBox.MouseClick += OnHeaderCheckBoxMouseClick; grid.CellValueChanged += OnGridCellValueChanged; grid.CurrentCellDirtyStateChanged += OnGridCurrentCellDirtyStateChanged; grid.CellPainting += OnGridCellPainting; }