Click here to Skip to main content
15,391,989 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am getting data on data grid view by searching name and now i want to get the details of that column on respective textboxes/label by clicking on that cell in which name is displayed.

1 solution

This may help you

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
    {            MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());

or you could use the gridview selection change event in that you could use like the following code.

int Selectedrow=gridvview.selectedindex;
string selectedcellvalue =(gridview.rows[Selectedrow].cells[0].text).ToString();

like this you can use for the other cell values like 0,1,2,3...
Anurag Sarkar 7-Aug-12 8:40am
If you find this as useful...mark as solution
_Amy 7-Aug-12 8:48am
My +5!
AshishChaudha 7-Aug-12 9:04am
my 5!
Anurag Sarkar 7-Aug-12 14:46pm
I dont want to show all the columns of the table on datagridview but i want to display the data of all columns on textbox PLease Help

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