![]() |
We will be using Event RowPostPaint. because it is widely used as an advanced-level programming language for a general technique to the developer.
Then copy code that I provided below and paste it inside the Datagridview Event RowPostPaint.
private void dgw_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { string strRowNumber = (string)((e.RowIndex + 1).ToString()); SizeF size = e.Graphics.MeasureString((string)((e.RowIndex + 1).ToString()), this.Font); if (dgw.RowHeadersWidth < Convert.ToInt32(size.Width + 20)) { dgw.RowHeadersWidth = Convert.ToInt32(size.Width + 20); } Brush b = SystemBrushes.ControlText; e.Graphics.DrawString(strRowNumber, this.Font, b, e.RowBounds.Location.X + 0, e.RowBounds.Location.Y + (System.Convert.ToInt32(e.RowBounds.Height - size.Height) / 2)); }
Post A Comment:
0 comments: