[C#]데이터 그리드 뷰(DataGridView)의 줄번호(행번호)보이도록 하기
private void dgvList_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
//===============================
//그리드 행번호 입력하는 부분
//===============================
if (e.ColumnIndex < 0 && e.RowIndex >= 0)
{
e.Paint(e.ClipBounds, DataGridViewPaintParts.All);
Rectangle _rect = e.CellBounds;
_rect.Inflate(-2, -2);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), e.CellStyle.Font, _rect, e.CellStyle.ForeColor, TextFormatFlags.Right);
e.Handled = true;
}
}
{
//===============================
//그리드 행번호 입력하는 부분
//===============================
if (e.ColumnIndex < 0 && e.RowIndex >= 0)
{
e.Paint(e.ClipBounds, DataGridViewPaintParts.All);
Rectangle _rect = e.CellBounds;
_rect.Inflate(-2, -2);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), e.CellStyle.Font, _rect, e.CellStyle.ForeColor, TextFormatFlags.Right);
e.Handled = true;
}
}
댓글
댓글 쓰기