Click here to Skip to main content
15,896,421 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
Posted
Updated 16-Jan-11 21:33pm
v3
Comments
Dalek Dave 17-Jan-11 3:33am    
Edited for Grammar, Syntax and Readability.

This video may help[^].
 
Share this answer
 
Comments
Dalek Dave 17-Jan-11 3:33am    
Good Link.
Abhinav S 17-Jan-11 3:35am    
Thanks DD.
Hello,

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();
srad.Show();
}
}
form 1 has properties:
public string clinicno;
public string ClinicNo
{
get;
set;
}

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

set
{
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 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