DataGridView相关代码
加行号:
private void dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { //添加行号 var dgv = sender as DataGridView; SolidBrush v_SolidBrush = new SolidBrush(dgv.RowHeadersDefaultCellStyle.ForeColor); int v_LineNo = 0; v_LineNo = e.RowIndex + 1; string v_Line = v_LineNo.ToString(); e.Graphics.DrawString(v_Line, e.InheritedRowStyle.Font, v_SolidBrush, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5); }