Morning Guys.. Have a Monday Morning Blank out here!

I have the following Debug code setup:

         //XML Load of Document. This loads the XML Document and the value of a Single Node then inputs this to a text box//
            XmlDocument doc = new XmlDocument();
            doc.Load("C:\\twDB.xml");
            XmlNode node = doc.SelectSingleNode("/DataBases/DataBase/Connection");
            this.textBox1.Text = node.InnerText;

Currently shows the path of XML in text box for Debugging.

However - How do I show that same information in form2.cs textbox1 ?

Minds gone blank.. need more coffee.

Regards
Mark.

Recommended Answers

All 5 Replies

How does form2 get shown? Are they both showing simultaneously?

Morning Kesuekiame,

It's called via a Label in the 1st form.

      private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //Opens Second Form - Not Used as yet//
            Form2 secondForm = new Form2();
            secondForm.Show();
        }

regards
Mark.

You can create a constructor for Form2 that accepts a string parameter and pass that value when showing the second form. Be sure to set the textbox text on second form on Init().

Okay, there's a couple of ways you can do it.

Firstly, have a public field through which you can set the value.
Secondly, call a public method which sets the value explicitly.

First:

Form2 secondForm = new Form2();
secondForm.ConnectionString = textBox1.Text;
secondForm.Show();


....

In Form2:

OnLoad(object sender, EventArgs evt)
{
    textBox1.Text = ConnectionString;
}

Second:

Form2 secondForm = new Form2();
secondForm.SetConnectionString(textBox1.Text);
secondForm.Show();

....

Form2:

public void SetConnectionString(String connectionString)
{
    textBox1.Text = connectionString;
}

Alternatively, use the constructor. The best way would be to use a configuration object that you can call from your second form (Singleton accessor) so you needn't pass the data around.

Ahhh..

There we go. All done... Thanks guys.. Coffee has finally kicked in.

All sorted

Thanks as always.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.