AdBlock Detected

We provide high-quality source code for free. Please consider disabling your AdBlocker to support our work.

Buy me a Coffee

Saved Tutorials

No saved posts yet.

Press Enter to see all results

Display Row Number In C# Windows Application Datagridview

By pushpam abhishek
Listen to this article


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 this post

pushpam abhishek

About pushpam abhishek

Pushpam Abhishek is a Software & web developer and designer who specializes in back-end as well as front-end development. If you'd like to connect with him, follow him on Twitter as @pushpambhshk

Comments