Link to home
Start Free TrialLog in
Avatar of Charles Baldo
Charles BaldoFlag for United States of America

asked on

c# Winforms: How to read a value form another form

Hi

New to c# Winforms.  I have a menu form that has a combox control on it. When I open up a form from that menu form, how can I read the value in the Menu Form on the form I just open up?

So I have in the menu form
MenuDesigner.cs
       this.RecordType = new System.Windows.Forms.ComboBox();

Menu.cs
      getContributions frm = new getContributions();
      frm.ShowDialog();

Thanks




then in my
SOLUTION
Avatar of jbachmanNET
jbachmanNET
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
NEVER make controls public! Create a special method to access values in a combobox, like in my code above:

        public string GetSelectedItemValueFromComboOnParent()
        {
            return mycombo.SelectedItem.ToString();
        }


Sometimes  it does make sense to set some values on a child form before displaying it (and not passing parent's reference to constructor). However, don't make child's controls public - create set properties or methods instead.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Charles Baldo

ASKER

Thanks Everyone learned a bunch and used anarkis solution