private void dataGridview1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex == 0 && e.RowIndex == -1)
{
e.PaintBackground(e.ClipBounds, false);
Point pt = e.CellBounds.Location; // where you want the bitmap in 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.CheckedChanged += new EventHandler(gvSheetListCheckBox_CheckedChanged);
((DataGridView)sender).Controls.Add(cb);
e.Handled = true;
}
}
private void gvSheetListCheckBox_CheckedChanged(object sender, EventArgs e)
{
//dataGridview1.ClearSelection();
//dataGridview1.CommitEdit(DataGridViewDataErrorContexts.Commit);
//foreach (DataGridViewRow r in dataGridview1.Rows)
//{
// r.Cells[0].Value = ((CheckBox)sender).Checked;
//}
dataGridview1.BeginEdit(true);
foreach (DataGridViewRow item in dataGridview1.Rows)
{
item.Cells[0].Value = ((CheckBox)sender).Checked;
}
dataGridview1.EndEdit();
}
'c샵' 카테고리의 다른 글
C# 클래스 배열 정렬 방법 (0) | 2017.04.24 |
---|---|
c# dateTime 시간 표현 (0) | 2017.04.23 |
c# datatGridview 셀 내용 위치설정 (0) | 2017.04.21 |
C# linkLabel 사용시 에러 뜰때 (0) | 2017.04.21 |
C# htmlagilitypack 으로 from접근 (0) | 2017.04.19 |