본문 바로가기

Tip !!!/C# tip

DataGridView에 Row Index 표시하기

dataGrid _RowPostPaint event함수 사용

그냥 복사해서 사용하면 됨 ( 사각형그리고 인덱스 숫자 그리고...)


 

private void dataGrid_RowPostPaint(object sender,    DataGridViewRowPostPaintEventArgs e)

{
    Rectangle rect = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y,
                                    dataGrid.RowHeadersWidth - 4, e.RowBounds.Height);
    TextRenderer.DrawText(e.Graphics, (e.RowIndex).ToString(), dataGrid.RowHeadersDefaultCellStyle.Font,
                                     rect,dataGrid.RowHeadersDefaultCellStyle.ForeColor,
                                     TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}// func