?
Solved

Pass a combobox selected value between window forms

Posted on 2009-04-24
4
Medium Priority
?
542 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:leap29
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 24223511
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 24223516
0
 
LVL 3

Accepted Solution

by:
Aleksei_Malkov earned 1000 total points
ID: 24236299
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
 

Author Closing Comment

by:leap29
ID: 31574160
Perfect,

thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Screencast - Getting to Know the Pipeline
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question