Pass a combobox selected value between window forms

I'm trying pass the value of a combo box between two window forms.  I've had a read up on this but I've just ended up very confused!!!

can you please help me with a very simple straight forward method to dothis??

Thanks
leap29Asked:
Who is Participating?
 
Aleksei_MalkovConnect With a Mentor Commented:
In form with combo box - create static property which will return selected value.
In any other form you can use this static property...
    public partial class Form_Withcombo : Form
    {
        private static object selectedValue = string.Empty;
 
        public static object SelectedValue
        {
            get { return selectedValue; }
        }
 
 
        public Form_Withcombo()
        {
            InitializeComponent();
            this.comboBox1.SelectedValueChanged += new System.EventHandler(this.comboBox1_SelectedValueChanged);
        }
 
        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            selectedValue = comboBox1.SelectedValue;
        }
    }
 
    public class Form2 : Form 
    {
        public void F()
        {
            Console.WriteLine(Form_Withcombo.SelectedValue);
            // here you can user Form_WithCombo.SelectedValue
        }
    }

Open in new window

0
 
DhaestCommented:
There are so many methods (How many? I don't know) to pass data between forms in Windows application. In this article, let me take four important (easiest) ways of accomplishing this:

1. Using constructor
2. Using objects
3. Using properties
4. Using delegates

More info: http://www.codeproject.com/KB/cs/pass_data_between_forms.aspx
0
 
leap29Author Commented:
Perfect,

thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.