Click here to Skip to main content
13,147,689 members (32,792 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
Updated 17-Nov-12 6:04am
@AmitGajjar 17-Nov-12 11:43am
you want number of rows or number of columns ?
meme_307 17-Nov-12 11:45am
i want number of row to use it in update and delete
Sergey Alexandrovich Kryukov 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 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 17-Nov-12 13:05pm
i want to save the index of row in database
ridoy 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2017
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