Microsoft Knowledge Base Email Alertz

KBAlertz.com: (193241) - In some circumstances, it is necessary to create two or more forms that are independent of each other while keeping the data displayed in the forms synchronized. This article demonstrates how to synchronize the data displayed on two independent forms.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 193241 - Last Review: July 13, 2004 - Revision: 2.2

How To Synchronize Data Displayed on Two Different Forms

This article was previously published under Q193241

SUMMARY

In some circumstances, it is necessary to create two or more forms that are independent of each other while keeping the data displayed in the forms synchronized. This article demonstrates how to synchronize the data displayed on two independent forms.

MORE INFORMATION

In order to synchronize the data display between two or more independent forms, it is necessary to call the refresh method of the form(s) that contain the data that needs to be refreshed. The methods available for refreshing a form after moving a record pointer are to some extent dependent on how the form is being instantiated.

The following example illustrates use of the Refresh method between two forms:

  1. Create a form named TEST1 and change the Caption property to "Employee Form."
  2. Add the EMPLOYEE table from the \\SAMPLES\DATA directory to the form's DataEnvironment and set the ORDER to EMP_ID.
  3. Drag the following fields from the EMPLOYEE table to the form:
          EMPLOYEE.EMP_ID
          EMPLOYEE.LAST_NAME
          EMPLOYEE.FIRST_NAME
          EMPLOYEE.TITLE
  4. Add the following code to the form's Init event:
          DO FORM TEST2
  5. Create a form named TEST2 and change the Caption property to "Search Form." Add the EMPLOYEE table from the \\SAMPLES\DATA directory to the form's DataEnvironment and set the ORDER to EMP_ID. In the form's DataEnvironment and set the following values:
          AutoCloseTables=.F.
          AutoOpenTables=.F.
  6. Add a list box control that has the following values to the form:
          RowSourceType=6 - Fields
          RowSource=EMPLOYEE.EMP_ID
    							
  7. Add the following code to the Click event of the list box control:
          IF !EMPTY(THIS.VALUE)
             IF SEEK(RTRIM(THIS.VALUE))
                * Note that TEST1 is the name of the .SCX file created earlier
                test1.REFRESH
             ENDIF
          ENDIF
    							
  8. Save the form.
  9. From the command line type "DO FORM TEST1" and use the form captioned "Search Form" to move the record pointer. After you click a value in the list box, the data in the "Employee Form" refreshes.
If the form is being instantiated from a class definition, refreshing the form becomes somewhat more problematic. In this case, the FORMS collection must be used to refresh the target form(s).

The following code illustrates use of the FORMS collection to refresh another form:

  1. Create a program file called Demo.prg that contains the following code:
          * Begin Code
          PUBLIC ox
          ox=CREATEOBJECT('SYNCHED1')
          ox.SHOW
    
          DEFINE CLASS synched1 AS FORM
             TOP = 50
             LEFT = 162
             HEIGHT = 160
             WIDTH = 310
             DOCREATE = .T.
             CAPTION = "Employee Form"
             NAME = "Form1"
             AUTOCENTER=.T.
    
             ADD OBJECT lblemp_id AS LABEL WITH ;
                AUTOSIZE = .T., ;
                BACKSTYLE = 0, ;
                CAPTION = "Employee ID", ;
                LEFT = 11, ;
                TOP = 0, ;
                TABINDEX = 3, ;
                NAME = "lblEmp_id"
    
             ADD OBJECT lbllast_name AS LABEL WITH ;
                AUTOSIZE = .T., ;
                BACKSTYLE = 0, ;
                CAPTION = "Last Name", ;
                LEFT = 11, ;
                TOP = 36, ;
                TABINDEX = 5, ;
                NAME = "lblLast_name"
    
             ADD OBJECT lblfirst_name AS LABEL WITH ;
                AUTOSIZE = .T., ;
                BACKSTYLE = 0, ;
                CAPTION = "First Name", ;
                LEFT = 11, ;
                TOP = 72, ;
                TABINDEX = 7, ;
                NAME = "lblFirst_name"
    
             ADD OBJECT lbltitle AS LABEL WITH ;
                AUTOSIZE = .T., ;
                BACKSTYLE = 0, ;
                CAPTION = "Title", ;
                LEFT = 11, ;
                TOP = 108, ;
                TABINDEX = 9, ;
                NAME = "lblTitle"
    
             ADD OBJECT txtemp_id AS TEXTBOX WITH ;
                CONTROLSOURCE = "employee.emp_id", ;
                HEIGHT = 23, ;
                LEFT = 84, ;
                MAXLENGTH = 6, ;
                TABINDEX = 4, ;
                TOP = 0, ;
                WIDTH = 53, ;
                NAME = "txtEmp_id"
    
             ADD OBJECT txtlast_name AS TEXTBOX WITH ;
                CONTROLSOURCE = "employee.last_name", ;
                HEIGHT = 23, ;
                LEFT = 84, ;
                MAXLENGTH = 20, ;
                TABINDEX = 6, ;
                TOP = 36, ;
                WIDTH = 149, ;
                NAME = "txtLast_name"
    
             ADD OBJECT txtfirst_name AS TEXTBOX WITH ;
                CONTROLSOURCE = "employee.first_name", ;
                HEIGHT = 23, ;
                LEFT = 84, ;
                MAXLENGTH = 10, ;
                TABINDEX = 8, ;
                TOP = 72, ;
                WIDTH = 80, ;
                NAME = "txtFirst_name"
    
             ADD OBJECT txttitle AS TEXTBOX WITH ;
                CONTROLSOURCE = "employee.title", ;
                HEIGHT = 23, ;
                LEFT = 84, ;
                MAXLENGTH = 30, ;
                TABINDEX = 10, ;
                TOP = 108, ;
                WIDTH = 218, ;
                NAME = "txtTitle"
    
             PROCEDURE LOAD
                PUBLIC varval
                IF ATC("Visual FoxPro 06.",VERSION())>0
                USE Home(2)+"Employee.dbf"
                Else
                USE home()+"\samples\data\employee"
                ENDIF
                SET ORDER TO TAG emp_id
                GO TOP
                STORE SPACE(LEN(employee.emp_id)) TO m.varval
             ENDPROC
    
             PROCEDURE DESTROY
                FOR i=1 TO _SCREEN.FORMCOUNT
                   * Look for the Search Form in the FORMS collection.
                   IF _SCREEN.FORMS(i).CAPTION="Search Form"
                      * If the Search Form exists, release it
                      _SCREEN.FORMS(i).RELEASE
                   ENDIF
                ENDFOR
                * Close the table.
                SELECT employee
                USE
             ENDPROC
    
             PROCEDURE INIT
                * Launch the Search Form.
                PUBLIC search
                search=CREATEOBJECT('SYNCHED2')
                search.SHOW
             ENDPROC
          ENDDEFINE
    
          DEFINE CLASS synched2 AS FORM
             TOP = 0
             LEFT = 0
             HEIGHT = 118
             WIDTH = 205
             DOCREATE = .T.
             CAPTION = "Search Form"
             NAME = "Form2"
    
             ADD OBJECT list1 AS LISTBOX WITH ;
                ROWSOURCETYPE = 0, ;
                HEIGHT = 96, ;
                LEFT = 24, ;
                TOP = 12, ;
                WIDTH = 145, ;
                NAME = "List1"
    
             PROCEDURE INIT
                THIS.list1.ROWSOURCETYPE=1
                IF USED('EMPLOYEE')
                   SELECT employee
                   currec=RECNO()
                   GO TOP
                   SCAN
                      * Load the list box with data from the table.
                      THIS.list1.ADDLISTITEM(employee.emp_id)
                   ENDSCAN
                   GOTO currec
                ENDIF
             ENDPROC
    
             PROCEDURE list1.CLICK
                IF !EMPTY(THIS.VALUE)
                   SELECT employee
                   IF SEEK(RTRIM(THIS.VALUE))
                      * Move the record pointer
                      FOR i=1 TO _SCREEN.FORMCOUNT
                         * Look for the Employee Form in the FORMS collection.
                         IF _SCREEN.FORMS(i).CAPTION="Employee Form"
                            * If the Employee Form exists, Refresh it
                            _SCREEN.FORMS(i).REFRESH
                         ENDIF
                      ENDFOR
                   ENDIF
                ENDIF
             ENDPROC
    
             PROCEDURE DESTROY
                FOR i=1 TO _SCREEN.FORMCOUNT
                   * Look for the Employee Form in the FORMS collection.
                   IF _SCREEN.FORMS(i).CAPTION="Employee Form"
                      * If the Employee Form exists, release it
                      _SCREEN.FORMS(i).RELEASE
                   ENDIF
                ENDFOR
             ENDPROC
          ENDDEFINE
          * End Code.
    							
  2. From the command line type "DO DEMO" and use the form captioned "Search Form" to move the record pointer. After clicking a value in the list box, the data in the Employee Form refreshes.

REFERENCES

(c) Microsoft Corporation 1998. All Rights Reserved. Contributions by John Desch, Microsoft Corporation

APPLIES TO
  • Microsoft Visual FoxPro 3.0b for Macintosh
  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 3.0b Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 5.0a
  • Microsoft Visual FoxPro 6.0 Professional Edition
Keywords: 
kbcode kbhowto KB193241
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please