DataGridView컬럼헤더에 Checkbox넣기
DataGridView의 이벤트중 CellPainting 나 Load이벤트에
if (e.ColumnIndex == 0 && e.RowIndex == -1)
{
e.PaintBackground(e.ClipBounds, false);
Point pt = e.CellBounds.Location;the cell
int nChkBoxWidth = 15;
int nChkBoxHeight = 15;
int offsetx = (e.CellBounds.Width - nChkBoxWidth) / 2;
int offsety = (e.CellBounds.Height - nChkBoxHeight) / 2;
pt.X += offsetx;
pt.Y += offsety;
CheckBox cb = new CheckBox();
cb.Size = new Size(nChkBoxWidth, nChkBoxHeight);
cb.Location = pt;
cb.Checked = true;
cb.CheckedChanged += new EventHandler(dgvCheckBox_CheckedChanged);
((DataGridView)sender).Controls.Add(cb);
e.Handled = true;
}
해당코드 입력
넣고자 하는 컬럼헤더에 Check박스위치를 계산해서 새로 그려주는 코드와 체크박스 이벤트 추가하는 코드임