Display selected row from DataGrid to TextBoxes. drag and down a DataGrid view and double click on DataGrid view.
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{SqlConnection con = new SqlConnection("server = MUNESH\\SQL2008R2;Database=data;UID=sa;Password=123;");
DataGridViewCell cell = null;
foreach (DataGridViewCell selectedCell in dataGridView1.SelectedCells)
{
cell = selectedCell;
break;
}
if (cell != null)
{
DataGridViewRow row = cell.OwningRow;
textBox1.Text = row.Cells["Name"].Value.ToString();
id_txt.Text = row.Cells["ID"].Value.ToString();
textBox3.Text = row.Cells["Age"].Value.ToString();
}
}

Munesh SharmaPosted Nov 3, 2015, 12:14 AM
Thank you
J NPosted Nov 1, 2015, 6:01 AM
Thanks Munesh. Helped me quite a bit. Just had to change the database values, the text boxes, and the Grid View name to my own. Worked first time.
selva kumarPosted Mar 20, 2014, 5:11 AM
Nice article dude...