Click here to Skip to main content
11,705,610 members (47,153 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
How can i retrieve the number of row from datagridview.

If I use this.
var a=  dataGridView1

I can't complete the code to retrieve the number of index to use it.
Posted 17-Nov-12 5:19am
Edited 17-Nov-12 6:04am
@AmitGajjar at 17-Nov-12 11:43am
you want number of rows or number of columns ?
meme_307 at 17-Nov-12 11:45am
i want number of row to use it in update and delete
Sergey Alexandrovich Kryukov at 17-Nov-12 23:18pm
What is "number of index"? :-)

1 solution

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

Solution 1

meme_307 at 17-Nov-12 13:00pm
var row = dataGridView1.CurrentCell.RowIndex;
label3.Text = row;
i want to use like this to retrieve the number of row but it give me error
meme_307 at 17-Nov-12 13:05pm
i want to save the index of row in database
ridoy at 17-Nov-12 13:43pm
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
int rowIndex1 = e.RowIndex;
int rowIndex2 = GetRowIndex();
private int GetRowIndex()
int rowIndex = this.dataGridView1.CurrentCell.RowIndex;
return rowIndex;
I use here 2 ways to find out index..i think you can easily convert it to

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

  Print Answers RSS
0 OriginalGriff 213
1 Sergey Alexandrovich Kryukov 160
2 Inimicos 60
3 ProgramFOX 50
4 Richard MacCutchan 45
0 OriginalGriff 9,053
1 Sergey Alexandrovich Kryukov 8,347
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,626

Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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