/// <summary>
/// DataGridView 의 RowHeader 에 일련번호 자동생성
/// </summary>
/// <param name="sender">DataGridView 컨트롤</param>
/// <param name="e">이벤트정보</param>
static void DGV_AutoRowIndex(object sender, DataGridViewRowPostPaintEventArgs e)
{
DataGridView dgv = sender as DataGridView;
try
{
if (dgv != null && dgv.Rows.Count > 0 && e.RowIndex >= 0)
{
String rowIdx = (e.RowIndex + 1).ToString();
StringFormat centerFormat = new StringFormat()
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
};
RectangleF headerBounds = new RectangleF(e.RowBounds.Left, e.RowBounds.Top, dgv.RowHeadersWidth, e.RowBounds.Height);
e.Graphics.DrawString(rowIdx, dgv.Font, SystemBrushes.ControlText, headerBounds, centerFormat);
}
}
catch (Exception ex)
{
KLog.Write(ex.ToString());
}
}
'유용한 정보' 카테고리의 다른 글
[C#] 컨트롤에 들어갈 문자열에서 가장 큰 폭과 높이 구하기 (0) | 2025.04.16 |
---|---|
[C#] DataGridView 에 수직스크롤바가 있는지의 여부 판단하기 (0) | 2025.04.16 |
[C#] DataGridView 의 데이터 검색하기 (0) | 2025.04.16 |
[C#] DataGridView에서 행이 비어있는지 체크 (0) | 2025.04.16 |
[C#] TextBox 컨트롤에 수직스크롤바가 있는지의 여부 판단하기 (0) | 2025.04.16 |