I have a datagrid and i want to add line no on that datagrid. I have searched and tried everything but not find the solution. Please help me with this.
That name of the datagrid is countResult.
So I have added another column but don't know how to set value to that column.
Write this code in your program.
Private Sub dataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles countResult.RowPostPaint Using b As SolidBrush = New SolidBrush(countResult.RowHeadersDefaultCellStyle.ForeColor) e.Graphics.DrawString(e.RowIndex.ToString(System.Globalization.CultureInfo.CurrentUICulture), _ countResult.DefaultCellStyle.Font, _ b, _ e.RowBounds.Location.X + 20, _ e.RowBounds.Location.Y + 4) End Using End Sub
It will print the line no on datagridview. Hope it will help.