Jampa Jampa - 1 year ago 84
Vb.net Question

how to add line number on datagrid without row that is already bounded to the database

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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download