RowPostPaint事件
private void datagridview1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { try { SolidBrush b = new SolidBrush(datagridview.RowHeadersDefaultCellStyle.ForeColor); e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), datagridview.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
文章来源: C# datagridview最左行显示序号