Many Click events of the DataGrridView show a DataGridViewCellEventArgs
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
// e.RowIndex and e.ColumnIndex
}
This class gives you access to the row and column.
ddanbe
Industrious Poster
4,287 posts since Oct 2008
Reputation Points: 2,121
Solved Threads: 722
Skill Endorsements: 26
I will only add to ddanbe` post:
If you are not in some dgv`s event handler you get the row number like:
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;
}
Mitja
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Depends on what your intentions are, as long as you know what you are doing, please add 1. No problem.
ddanbe
Industrious Poster
4,287 posts since Oct 2008
Reputation Points: 2,121
Solved Threads: 722
Skill Endorsements: 26
Yes you do:
if(dataGridView1.Rows.Count > 0)
{
//your code
}
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Question Answered as of 2 Years Ago by
ddanbe
and
Mitja Bonca