Accessing Control Form to another Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LeLouch Fenette
    New Member
    • Aug 2011
    • 16

    Accessing Control Form to another Form

    How to access a Control Form to Another form?
    For example:

    In Form1
    I have a datagrid named " dgview ".

    In Form2
    I want to access the dgview into Form2..

    "Form1.dgview.d atasource...... ...."
  • arvindps
    New Member
    • Sep 2011
    • 8

    #2
    why would you want to access datagridview in another form.

    Please always quote examples and sample data

    Comment

    • arie
      New Member
      • Sep 2011
      • 64

      #3
      If I have to do it I use public properties of Form1, which I access using Form2 Owner field (which is set to Form1).

      I know it's not elegant and ther's probably a better way to do it but it works.

      example:

      Form1:
      Code:
      public string MyProperty
      {
        get
        {
            return myTextBox.Text;
        }
        set
        {
            myTextBox.Text = value;
        }
      }
      then create Form2 as Form1 child form:
      Code:
      Form2 frm = new Form2();
      frm.Show(this);
      and finally in Form2, when you want to change text of your textbox:
      Code:
      this.Owner.MyProperty = "new text";

      Comment

      Working...