Display Row Number In C# Windows Application Datagridview

Display Row Number In C# Windows Application Datagridview
Share it:
Display Row Number In C# Windows Application Datagridview
google 
In these tutorials, we will learn Display Row Number In C# Windows Application Datagridview. This code will Auto-Generate Row Number in c# window application Datagridview. 
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));
        }
Share it:

C#

dotnet

Post A Comment:

0 comments: