DataGridView 이벤트에서 RowPostPaint를 추가하고


아래와 같이 코드를 넣으면 된다.

// 주석은 16진수 (4자리)


private void Gridview_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
            DataGridView grid = sender as DataGridView;
            //String rowIdx = (e.RowIndex + 1).ToString("X4");
            String rowIdx = (e.RowIndex + 1).ToString();
 
            StringFormat centerFormat = new StringFormat()
            {
                Alignment = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };
 
            Rectangle headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top,
                                                    grid.RowHeadersWidth, e.RowBounds.Height);
            e.Graphics.DrawString(rowIdx, this.Font, SystemBrushes.ControlText,
                                  headerBounds,centerFormat);
}


블로그 이미지

SherryBirkin

,