Click here to Skip to main content
15,936,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Could someone advise me of the simplest way to display all row information from a selected column in datagridview into a textbox?

My database consists of 4 columns but I only display one of the column in datagridview. Hence when one of the rows column is selected, I'd like to display the other rows of information from other columns into a textbox.
Posted
Comments
saguptamca 17-Jun-13 3:41am    
what hv u already done
dolphinlover2013 17-Jun-13 5:09am    
In my datagridview, I have displayed the column "Name".
Hence, when any of the rows' column is clicked, the information will transfer to the textbox. I've done the following code:

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > 0)
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
tbx_Name.Text = row.Cells["Name"].Value.ToString();
tbx_Description.Text = row.Cells["Description"].Value.ToString();
tbx_Id.Text = row.Cells["ID"].Value.ToString();
}

But unfortunately, only textbox(tbx_Name) has information not the other 2.
saguptamca 17-Jun-13 5:51am    
Try this and tell me if works. Otherwise we will try another way:
Use dataset to get values, by which u bound gridview.
or dont hide columns, just set their width to 0%
dolphinlover2013 17-Jun-13 9:47am    
My data are from SQL server and I call the data from my DBmanager. I don't manually type in the dataset inside.
saguptamca 17-Jun-13 10:06am    
saurabhmca1@gmail.com is my ID, if its ok with u. You can mail me current working code, I'll try to correct it. :)

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