Click here to Skip to main content
15,944,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all.

I've two forms, form1 & form2.
Form1 contains 4 text boxes, edit button and form2 contains DataGridView.

My question is that I want to display selected row data of DatagridView in respective text boxes as I click the edit button.

Tell me whether this code is correct,
for1.txtCode.Text = dgvAdrsMstr.SelectedRows[0].Cells[0].Value.ToString();//and this is not retrieve data 

Help me out
Updated 16-Jan-11 21:33pm
Dalek Dave 17-Jan-11 3:33am    
Edited for Grammar, Syntax and Readability.


my Form1 is having a gridview with some values in it.form2 having textboxes. As soon as i click on row in grid view those items populate in textboxes.For this.
My form 1 with gridview contains follwing code:

private void button_Click(object sender, EventArgs e)
for (int i = 0; i < studRecGridView.Rows.Count; i++)

DataGridViewRow selrow = studRecGridView.Rows[i];
if (selrow.Selected == true)

clinicno = selrow.Cells["Clinic No"].Value.ToString();// retrieves value from gridview clicnic no column.

SRadFrm srad = new SRadFrm();
srad.ClinicNum = clinicno.ToString();
form 1 has properties:
public string clinicno;
public string ClinicNo

Form2 with textboxes has follwing properties
private string clinicnum;
public string ClinicNum
return clinicnum;

clinicnum = value;
textBox1.Text = value;
form 2 has a textbox where gridview clinic no gets populated;
private void textBox1_TextChanged(object sender, EventArgs e)
textBox1.Text = ClinicNum;


this code works for me..Hope it helps u too!
Share this answer
This video may help[^].
Share this answer
Dalek Dave 17-Jan-11 3:33am    
Good Link.
Abhinav S 17-Jan-11 3:35am    
Thanks DD.

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