Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can i retrieve the number of row from datagridview.

If I use this.
C#
var a=  dataGridView1


I can't complete the code to retrieve the number of index to use it.
Posted
Updated 17-Nov-12 6:04am
v2
Comments
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"? :-)
--SA

1 solution

 
Share this answer
 
Comments
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 vb.net..

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