WinForm给DataGridView增加序号
1 /// <summary> 2 /// 增加序号 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="e"></param> 6 private void uiDataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) 7 { 8 Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, 9 e.RowBounds.Location.Y, 10 this.uiDataGridView1.RowHeadersWidth - 4, 11 e.RowBounds.Height); 12 13 TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), 14 this.uiDataGridView1.RowHeadersDefaultCellStyle.Font, 15 rectangle, 16 this.uiDataGridView1.RowHeadersDefaultCellStyle.ForeColor, 17 TextFormatFlags.VerticalCenter | TextFormatFlags.Right); 18 19 }