0

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.

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by megdan
0

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.

Edited by mvxg

0

Hi you can also you property or public variable.

Edited by pritaeas: Do not mention, plug or refer to any product, service, or website you are affiliated with anywhere outside of Business Exchange forums

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.