PDA

Click to See Complete Forum and Search --> : Reference a control from another form


packman
Jul 9th, 2002, 08:35 AM
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

hellswraith
Jul 9th, 2002, 12:56 PM
Check out this post:
http://www.vbforums.com/showthread.php?s=&threadid=178810

BryanJ
Jul 9th, 2002, 05:19 PM
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