954,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

retreive value into textbox from form1 to form2

Hi everybody,
i am newbie working on a small application using c# .net

problem:

i have two forms, form1 and fom2.
i have textbox in both forms.
when i click the submit button i want to get the value from a form1 textbox into the form2 textbox automatically.

code:
// in form2


private void textBox12_TextChanged(object sender, EventArgs e)
{
textBox12 = Admin_Calculator.textBox13.Text;
}


Error:

An object reference is required for the non-static field, method, or property 'WindowsFormsApplication3.Form1.textBox13'


OR

is there any other alternative way to acheive this..
please help me with issue

mohdabid
Newbie Poster
3 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

How is your application set up?

Is Admin_Calculator the name of the Form or is it an instance of the form you have created? Do you create an instance of the form to show with the .Show() method?

bcasp
Light Poster
46 posts since Apr 2008
Reputation Points: 23
Solved Threads: 10
 

Admin_Calculator is the name of the form from where i want to get the value into form2 textbox

mohdabid
Newbie Poster
3 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

To do what you're trying to do, you're probably going to need to create an instance of the Admin_Calculator class.

How do you open the forms right now? Do you click something on one of the forms that causes the other to open?

bcasp
Light Poster
46 posts since Apr 2008
Reputation Points: 23
Solved Threads: 10
 

here's the code....

//FORM1

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;



namespace WindowsFormsApplication3
{
    public partial class Admin_Calculator : Form
    {
        public Admin_Calculator()
        {
            InitializeComponent();
        }

        private decimal MultiplyNumbers(decimal number1, decimal number2)
        {
            return number1 * number2;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            decimal value1 = decimal.Parse (SPOT.Text);
            decimal value2 = decimal.Parse (textBox2.Text);
            decimal returnValue1 = MultiplyNumbers(value1, value2);
            textBox13.Text = returnValue1.ToString();
       

    }
}

}

------------------------------------

//FORM2

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Display_Calculator : Form
    {
        public Display_Calculator()
        {
            InitializeComponent();
        }

        private decimal MultiplyNumbers(decimal number1, decimal number2)
        {
            return number1 * number2;
        }


        private void button1_Click(object sender, EventArgs e)
        {
            decimal value1 = decimal.Parse(textBox12.Text);
            decimal value2 = decimal.Parse(textBox18.Text);
            decimal returnValue1 = MultiplyNumbers(value1, value2);
            textBox24.Text = returnValue1.ToString();
        }

        private void textBox12_TextChanged(object sender, EventArgs e)
        {
            textBox12 = Admin_Calculator.textBox13.Text;
        }
    }
}


these two forms are independent, there is no button on form1 which opens the form2...

mohdabid
Newbie Poster
3 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You