728x90
728x170
private void DataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
   
var grid = sender as DataGridView;
   
var rowIdx = (e.RowIndex + 1).ToString();

   
var centerFormat = new StringFormat()
   
{
       
// right alignment might actually make more sense for numbers
       
Alignment = StringAlignment.Center,
       
LineAlignment = StringAlignment.Center
   
};

   
var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);
    e
.Graphics.DrawString(rowIdx, this.Font, SystemBrushes.ControlText, headerBounds, centerFormat);
}

 

위 방법이 제일 깔끔하게 표현이 되는것 같다.

728x90
그리드형
Posted by kjun.kr
,