Reputation: 1
I have a problem displaying the data on text boxes when clicked on DataGridView because I show only fullname and student id column on DataGridView.
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("SELECT Student_ID as S_ID, Fname +' '+ Lname +' '+ Mname as NAME from student", con);
DataTable dtbl = new DataTable();
sda.Fill(dtbl);
dataGridView1.DataSource = dtbl;
dataGridView1.Columns[0].Width = 40;
dataGridView1.Columns[1].Width = 200;
dataGridView1.RowHeadersVisible = false;
con.Close();
Upvotes: 0
Views: 3511
Reputation: 328
So, If I understand you correctly. When you're clicking on a datagridview cell you wanna display the information in the textboxes?
Start with this:
From here you can select the data from datagridview, and insert it into the textbox like this:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
YourTextBoxName.Text = dataGridView1.CurrentRow.Cells["Lname"].Value.ToString();
}
Upvotes: 2