I have a C# windows app that has two forms Form1 which is the main form and Form2. Form1 has a combobox on it and Form2 has a textbox.
I want to put the value selected in the Form1.ComboBox1 into Form2.TextBox1.
I am trying this:
Form1 Form1Object = new Form1();
string fff = Form1Object.ComboBox1.SelectedItem.ToString(); //not working
TextBox1.Text = fff;
Problem is that when I run this Form1 is reinitialized and i don't want that. (I have a splash screen that runt when the application starts so when i run my code the splashscreen starts all over again.
Is there a way to read ComboBox1 value without restarting the first form? If I try it directly it does not work, it sees the Form1 as calss instead of object.
Form1.ComboBox1.SelectedItem.ToString(); //does not work
I am also trying to add the value to the textbox when opening the second form:
Form2 form2 = new Form2();
form2.TextBox1.Text = ComboBox1.SelectedValue.ToString();
form2.Show();
This gives me the following error: "Object reference not set to an instant of an object."
EDIT: It works using this code:
Form2 form2 = new Form2();
form2.TextBox1.Text = ComboBox1.Text;
form2.Show();
Now my question still remains: If i am in Form2 can i still get the value from form1? If not, that is ok. I will post this as a solution.