Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
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.



C#
 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();
        }
Posted
Updated 1-Apr-15 3:28am
v2

1 solution

 
Share this answer
 
Comments
CHill60 1-Apr-15 9:38am    
5'd - I went straight for SA's article too!
Maciej Los 1-Apr-15 14:37pm    
Thank you, Caroline ;)
Bacanzela 1-Apr-15 9:55am    
Meaning ?
Sergey Alexandrovich Kryukov 1-Apr-15 10:40am    
Meaning what? First of all, none of your forms is a child of other form, this is a misconception.
You got detailed explanation on what you can do.
—SA
Sergey Alexandrovich Kryukov 1-Apr-15 10:49am    
Maciej, did you see my Skype messages on weekend, after you wanted to talk? About my article...
—SA

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