Ronald Caymo
Ronald Caymo

Reputation: 1

Display data in TextBox that clicked on DataGridView

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();

this

Upvotes: 0

Views: 3511

Answers (1)

Putte
Putte

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:

  • Click on your datagridview. -> Select Events -> Double click on "CellContentClick"

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

Related Questions