第一步:
private void BoxDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{if (e.RowIndex == -1 & e.ColumnIndex == 0)
{
Point p = GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location;
p.Offset(2, 0);
SelectAll.Location = p;
SelectAll.Size = GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Size;
SelectAll.Visible = true;
SelectAll.BringToFront();
}
}
在实现cellPainting在里面加入一个checkbox,这个是在列头加入
第二步:
private void SelectAll_CheckedChanged(object sender, EventArgs e)
{
EndEdit(DataGridViewDataErrorContexts.Commit);