Control access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ventsislav
    New Member
    • Mar 2009
    • 16

    Control access

    I want to transfer items from the combo boxes (those in F2 are public) in Form2 to those in Form1. Why' s not working like this?

    Form2

    Code:
    public partial class Form2 : Form
    {
        Form1 form1 = new Form1();
    
        ...
    
        private void button1_Click(object sender, EventArgs e)
        {
            form1.comboBox1.Items.Add(this.comboBox1.SelectedItem.ToString());
            form1.comboBox2.Items.Add(this.comboBox2.SelectedItem.ToString());
        }
    }
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    What you've shown is fine, but I'll bet it's not what you meant.

    You have made a NEW instance of a Form1 form, then put everything into your new Form1.

    Is that what you meant, or were you trying to move combobox contents into an already existing Form1?

    Comment

    • GaryTexmo
      Recognized Expert Top Contributor
      • Jul 2009
      • 1501

      #3
      It could be an access thing... is combobox1 in Form1 a private member? You might want to declare a public property for access.

      Comment

      • ventsislav
        New Member
        • Mar 2009
        • 16

        #4
        I fixed it. Made it static and called it from F2 with Form1.. Thanks!

        Comment

        Working...