Results 1 to 3 of 3

Thread: Reference a control from another form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    71

    Reference a control from another form

    Can anyone tell me how to reference a control from another form?
    For example, form1 has a populated datagrid on it. While form1 is still visible, the operator can click a button and form2 will appear on the top half of form1 (datagrid still visible for form1). Form2 is used to insert data into a database table. A routine is called that populates the datagrid. However, since this routine is in form2 and the datagrid is on form1, the IDE gives an error. In VB6 all I had to do in order to reference the datagrid on form1 from form2 is: FORM1.DATAGRID. How do I accomplish this in VB.Net. Thanks

  2. #2
    hellswraith
    Guest

  3. #3
    Addicted Member
    Join Date
    Nov 2000
    Location
    San Diego - California
    Posts
    251
    One way is to declare a reference to the type of control in a Module as public. Then in form1 set the reference then you can use the reference in form2. ie

    In a module declare

    Public grdData as datagrid 'Declare the reference

    In form1 set the reference

    grdData = MyDataGrid 'MyDataGrid is the control on form1


    Then on form2 you will have access to all the properties of MyDataGrid by just using grdData

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width