Enos

Enos

  • NA
  • 140
  • 26.2k

How to pass data from childform to parentform ?

Apr 1 2015 9:11 AM
I have two forms ,Form1 and Form2.
Form1 - Parent
Form2 - Child
Form1 Contains the following,
Textbox - it loads the file path,
Datagridview - it loads the file with its data,
ButtonNext -when button cliked it opens Form2,
Form2 Contains the following,
BrowseButton - it broswe for the file from the directory
Textbox - it then shows the path
ButtonFinish - it will tabes you back to Form1
*Now i want to access datagridview from Form1(Parent) from Form2(child). Now i can broswe the file on Form2 and when i click finish i can see my file path on Form1(parent) from the textbox but with no databeing loaded.
How can i load the data on Form1 into the datagridview ?
this is my code so far..
Form2.
public frmInputFile(frmMain_Page _frmMain)
{
InitializeComponent();
this._frmMain = _frmMain;
}
private void btnBrowse_Click(object sender, EventArgs e)
{
BrowseFile();
}
private void btnFinish_Click(object sender,EventArgs e)
{
_frmMain.SetFilepath(txtInputfile.Text);
_grid.Rows.Clear(); //cant get the grid from form1
string PathSelection = "";
if (txtInputfile.Text.Length > 0)
{
PathSelection = txtInputfile.Text;
}
oDataSet = new DataSet();
XmlReadMode omode = oDataSet.ReadXml(PathSelection);
for (int i = 0; i < oDataSet.Tables[2].Rows.Count; i++)
{
string comment = oDataSet.Tables["data"].Rows[i][2].ToString();
string font = Between(comment, "[Font]", "[/Font]");
string datestamp = Between(comment, "[DateStamp]", "[/DateStamp]");
string commentVal = Between(comment, "[Comment]", "[/Comment]");
string[] row = new string[] { oDataSet.Tables["data"].Rows[i][0].ToString(), oDataSet.Tables["data"].Rows[i][1].ToString(), font, datestamp, commentVal };
_grid.Rows.Add(row);
}
this.Hide();
Program._MainPage.Show();
Form1
private void btnLoadfile_Click(object sender, EventArgs e)
{
frmInputFile frmInput = new frmInputFile(this);
frmInput.Show();
}
public void SetFilepath(string Filepath)
{
txtInputfile.Text = Filepath;
}
//I dont know how i can handle the gridview here
public void Loadgrid(string LoadGrid)
{
Gridview_Input.ToString();
}

Answers (1)