Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Dear, Budds
how are you
my issue is that i have a Datagrideview on my VB.net Form , how can i auto generate serial number by adding a new row Datagrideview

"I hope it more clear"

Thanks in advanced
Posted
Updated 15-Jan-12 20:31pm
v3
Comments
Amir Mahfoozi 11-Jan-12 6:20am    
What do you mean by saying unregenerate ?
Dave Kreskowiak 11-Jan-12 10:03am    
And what do you mean by "SN"??
Sergey Alexandrovich Kryukov 11-Jan-12 23:18pm    
Can you make it clear? Please use "Improve question" above.
--SA

1 solution

below code shows how to do that.

Just you need to pass your datagridview in below function and it will generate auto number to Header cell.

NOTE: First you have to bind the datagridview with data then call the below function.

VB
Public Sub AutoNumberRowsForGridView(ByVal dataGridView As DataGridView)

    If dataGridView IsNot Nothing Then

    Dim count As Integer = 0

    While (count <= (dataGridView.Rows.Count - 2))

    dataGridView.Rows(count).HeaderCell.Value = String.Format((count + 1).ToString(), "0")

    count += 1

    End While

    End If

End Sub

Or Go through this link-
how-to-add-an-autonumber-column-in-a-datagridview/[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900