Click here to Skip to main content
13,736,491 members
Rate this:
 
Please Sign up or sign in to vote.
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 13-Oct-18 6:39am
Updated 5 days ago
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 5 days ago
   
What's for?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180920.1 | Last Updated 14 Oct 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100