Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.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.

I have got a search text box i got data in the datagridview by searching now i want to display all the records related to the specefic person on the label /textbox.

there are multiple records i am displaying some on datagridview and rest on textboxes so i want when user clicks on the datagridview data related to that person should be display on texboxes
Posted
Updated 7-Aug-12 10:30am
v6
Comments
[no name] 7-Aug-12 15:29pm    
Pretend for a second that you are reading this for the first time and forget that you know anything about your project.... could you figure out what it is that you are trying to do? We can't either.
Sandeep Mewara 7-Aug-12 15:39pm    
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.
Anurag Sarkar 7-Aug-12 15:40pm    
i have got a search text box i got data in the datagridview by searching now i want to display all the records related to the specefic person on the label /textbox.
Anurag Sarkar 7-Aug-12 15:44pm    
now please see if you can help
Anurag Sarkar 7-Aug-12 15:46pm    
there are multiple records i am displaying some on datagridview and rest on textboxes so i want when user clicks on the datagridview data related to that person should be display on texboxes

You can use below code to get the selected value of the cell of dataGridView.

Use this code on CellContentClick event of the dataGridView.

C#
{
//txtbox should get value from selected cell on
txtbox.Text = dataGridView1.SelectedCells[e.selectedCells].Value.ToString();
} 
 
Share this answer
 
v3
Comments
Abdul Quader Mamun 14-Aug-12 3:56am    
nice answer!
The event CellContentClick() can be used to identify which column(cell) is clicked by the user. See the following example,

C#
private void GridViewUpdataedConstituents_CellContentClick(object sender, DataGridViewCellEventArgs e)
       {
//Get the index of the cell clicked
           iSelectedGridIndex = gridView1.CurrentCell.ColumnIndex;

          //Now get the values of the clicked cell 
          txtSelectedValue.Text = gridView1.CurrentCell.Value.ToString();
}


The event CellContentClick() is belongs to DataGridView. You can get this event by simply double click on any DataGridView on Windows 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