Im a student working on an application in c#. In the firstpage of my application a user selects an item eg 'Room1' from combobox which is databinded to a database, i want the same selected item to display in a label on another form in the application. (ie i also want 'Room1' to display in a label on another form).

Please it is urgent.

Thanks for your help.

Hi,
In the second form create a constructor that takes a string as a parameter. There, after InitializeComponent method, assign your string to the label. For example:

public Form2(string selectedValue) 
        {
            InitializeComponent();
            label1.Text = selectedValue;
        }

You can get your selected item and display another form in the following way:

new Form2(comboBox1.SelectedItem.ToString()).Show();

comboBox1 is a combobox from which you want to take selected value.

Hi you can also you property or public variable.

Thanks, but how did you get the 'selectedValue' variable you usd in the consrtructor

Thanks, but how did you get the 'selectedValue' variable you usd in the consrtructor

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.