Click here to Skip to main content
15,902,492 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Auto generate row number in DataGridView in windows application


What I have tried:

How to Auto generate row number in DataGridView in windows application
Posted
Updated 14-Oct-18 5:23am
Comments
Afzaal Ahmad Zeeshan 13-Oct-18 12:58pm    
You can use another field, that acts like a row number. No?
Richard MacCutchan 13-Oct-18 13:08pm    
A DataGridView is already numbered. Rows are numbered from zero.
Maciej Los 14-Oct-18 14:04pm    
What's for?

1 solution

Write below code after bind gridview.
C#
foreach (DataGridViewRow row in dataGridView1.Rows)
               row.Cells["Index"].Value = (row.Index + 1).ToString();
 
Share this answer
 

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