Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We want to get Row and column index no. for the selected row in DataGridView. The code we used is as below, which is responding nothing. Please suggest how to do this.

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    string cellText = DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
    textBox1.Text = cellText;
}
Posted
Updated 13-May-11 7:37am
v2
Comments
Fabio V Silva 13-May-11 13:34pm    
What are you getting? What are you expecting?

try this :)
C#
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
   string cellText = e.RowIndex.ToString()+","+e.ColumnIndex.ToString();
   textBox1.Text = cellText;
}
 
Share this answer
 
Comments
RaviRanjanKr 15-May-11 7:25am    
Nice Answer, My 5 :)
ambarishtv 15-May-11 7:54am    
thanks ravi :)
its just look like u have 2 grids on form ?
 
Share this answer
 

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