Problem with passing data between forms.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kondi69
    New Member
    • Jun 2010
    • 1

    Problem with passing data between forms.

    Hello,

    I'm right newbe in c# but I have big problem with passing data between forms.

    Below code:

    [FORM2]:
    Code:
    public Form1 main = new Form1();
            public int opuwminuty;
            public Form2()
            {
                InitializeComponent();
                numericUpDown1.Value = main.uwminuty;
            }
    
            private void numericUpDown1_ValueChanged(object sender, EventArgs e)
            {
                opuwminuty = Convert.ToInt32(numericUpDown1.Value);
                try { opuwminuty = Convert.ToInt32(numericUpDown1.Value); }
                catch (Exception) { MessageBox.Show("pieprzy się w numericUpDown1"); }
                MessageBox.Show("opuwminty =" + opuwminuty + ", a main.uwminuty" + main.uwminuty);
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                main.uwminuty = opuwminuty;
                main.numericUpDown1.Value = opuwminuty;
    
                try { main.uwminuty = opuwminuty; }
                catch (Exception) { MessageBox.Show("pieprzy się w button1"); }
                MessageBox.Show("opuwminty =" + opuwminuty + ", a main.uwminuty" + main.uwminuty);
                //this.Close();
    
            }
    So for me all should be working, but in [FORM1] after changing value of numericupdown in form2 int uwminuty doesn't change its vaule... so [FORM1]
    Code:
    public int uwminuty;
    
     private void button10_Click(object sender, EventArgs e)
            {
                MessageBox.Show("uwminuty = " + uwminuty);
            }
    button10 always show old value! please help me to fix it! THANK YOU!

    I forgot to add that messagebox from button1 in form2 shows good values of opuwminuty and main.uwminuty.
    Last edited by kondi69; Jun 22 '10, 03:22 PM. Reason: forgotten
  • Joseph Martell
    Recognized Expert New Member
    • Jan 2010
    • 198

    #2
    You instantiate a Form1 in Form2, but I don't see where you ever show your form:

    Code:
    main.Show();
    Are you sure that whatever Form1 object you are clicking on is the same one that Form2.main references?

    Comment

    Working...