Hi, need help on getting the values from datagridview to textboxes, i am having a datagridview getting data's from SQL which has 4 column and number of rows retrieved from sql, i am having 4 textboxes, i want the datagridview selected row's column values to the textboxes, tried few things which i am getting error.
Kindly advice
Loading
Munesh SharmaPosted Sep 23, 2015, 1:34 AM
Andrew MillsPosted Sep 22, 2015, 3:16 PM
// The following code works perfect for me:
private void dgvCustomers_SelectionChanged(Object sender, EventArgs e)
{
MessageBox.Show("SelectionChanged event happened!");
DataGridViewRow row = this.dgvCustomers.SelectedRows[0];
txtID.Text = row.Cells[0].Value.ToString();
txtFirst.Text = row.Cells[1].Value.ToString();
txtLast.Text = row.Cells[2].Value.ToString();
}
//BUT, you must enter the following line in the load event
// to 'wire up' the event as there is nothing on the form
// in design view to double-click on to do this!
dgvCustomers.SelectionChanged += dgvCustomers_SelectionChanged;
VulpesPosted Oct 6, 2011, 2:49 PM
Prabhu RajaPosted Oct 6, 2011, 7:56 AM
You may use SelectedIndexChanged() Event of GridView Like,
-----------------------------------------------------------------
If this post helps you, then mark as "Correct Answer"
Thank You