Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm deveoping a window application ,having two forms. first form is calculating some values and diplaying in 4 text boxes,now i want to add these values to datagrid on other form.
Posted
Updated 21-Jul-10 1:59am
v2
Comments
OriginalGriff 21-Jul-10 8:21am    
What part of this is giving you problems?

Forms in C# are instances of classes themselves. So you could make 4 variables public and set their values before you close the form or switch back to the other form.

class form2
{
public string txtbox1;
public string txtbox2;
public string txtbox3;
public string txtbox4;
...
}


Wherever you call this form from.

form2 f2 = new form2();

if (f2.ShowDialog() == DialogResult.OK)
{
   //to get variables 
   f2.txtbox1; //etc... to retrive values
}


If this is unclear please let me know I will try to explain further.
 
Share this answer
 
If the source of the data grid is a table, you might want to add data to the table and simply show the grid.
It is not entirely clear what you want to achieve.
 
Share this answer
 
you can set the "Modifier" property on the text boxes to "Public" that would make them available for the other form2 so you could say like this on the form1

Form1 frm = new Form1();
if(frm.ShowDialog()==DialogResult.OK)
{
DataTable dtb=new DataTable();
dtb.Colums.Add("TextBoxValues");

dtb.Rows.Add(frm1.TextBox1.Text);
dtb.Rows.Add(frm1.TextBox2.Text);
dtb.Rows.Add(frm1.TextBox3.Text);
dtb.Rows.Add(frm1.TextBox4.Text);

DataGridView drg=new DataGridView();
drg.DataSource=dtb;
this.Controls.Add(drg);
}
 
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