pass Data Between Form

Posted by Hosseingholi under C# on 3/23/2010 | Views : 2172 | Status : [Member] | Replies : 3
I Have 2 Forms
both are loaded
i want with click in Datagrid Cells STRING Display In Text BOX in Other FORM
HOw CAN I DO?




Responses

Posted by: Syedshakeer on: 3/23/2010 [Member] Starter

Up
0
Down

In Form1:-
public partial class FormA : Form
{
Private void dataGridView1_CellContentClick_1(objectsender,DataGridViewCellEventArgs e)
{
i = dataGridView1.SelectedCells[0].RowIndex;
string fname=dataGridView1.Rows[i].Cell[0].Value.ToString();
string lname=dataGridView1.Rows[i].Cells[1].Value.ToString();
Form2 f2 = new Form2(fname,lname);
f2.Show();
}
}

In form2 Load Event:-
{
Form1 f1=Application.OpenForms(0);
txtfname.Text=f2.fname;
txtlanme.Text=f2.lanme;
}


Syed Shakeer Hussain

Hosseingholi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 3/23/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
Create a variable in Form1 which refer to the current reference of Form2.

Now when DataGrid cell is selected, use form2.TextBox1.Text to set the values directly to the 2nd form.



www.abhisheksur.com

Hosseingholi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarp on: 3/26/2010 [Member] Bronze

Up
0
Down
Hi friend


Read following Article

http://msdn.microsoft.com/en-us/library/aa728895%28VS.71%29.aspx 


Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Hosseingholi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response