tieboot
tieboot

Reputation: 3

Get textbox value from another value

I'm trying to add a new user in my listbox.

I'm opening a new form with 2 textboxes, name and email. But when i click 'add' and get back to the parent form, i try to get those values in strings, but the problem is that my strings are empty...

When i click on add in my new form, it just hides, so it returns back to the parent form.

After i clicked on the button in frm2 it return to this code. but the strings are empty.

  //nieuw form openen
            frm2.Text = "add person";
            frm2.ShowDialog();

              //check
              string naam = Program.f.txtname.Text, email = program.f.txtemail.Text;

            //adding to listbox and 'string' list collection
            lstemail.Items.Add(naam);
            stremails.Add(email);

To get to my second form i use this.

 static class Program
    {
        public static frmAdd f = new frmAdd();
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmemail());
        }
    }

Upvotes: 0

Views: 70

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125257

You don't need to use frm2 in such static way. you can create an instance of frm2 and use it.

1- Go to designer of frm2, select txtname and txtemail, then in propertygrid set value of Modifier to public.

2- write this code:

var f= new frm2();
f.ShowDialog();
string naam = f.txtname.Text
string email = f.txtemail.Text;
// do what you want with values...

Upvotes: 1

Related Questions