How to Set Gridview Row no

  • Gridview Set row No

    for further details and related topics
  • 1 Comment sorted by

  • This code will auto generate row no inDatagridview Header

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim con As New SqlConnection("Data Source=VM\SQLEXPRESS;Initial Catalog=LiveChat;Persist Security Info=True;User ID=sa;Password=zrg")
    Dim cmd As New SqlCommand("select * from asd", con)
    Dim da As New SqlDataAdapter(cmd)
    Dim dt As New DataTable
    DataGridView1.DataSource = dt

    End Sub

    Private Sub DataGridView1_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
    Using b As New SolidBrush(DataGridView1.RowHeadersDefaultCellStyle.ForeColor)
    e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + 4)
    End Using

    End Sub

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week