Microsoft KB Archive/142567

= How to filter a child grid by using a parent combo box in Visual FoxPro =

Article ID: 142567

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 7.0 Professional Edition
 * Microsoft Visual FoxPro 8.0 Professional Edition
 * Microsoft Visual FoxPro 9.0 Professional Edition

-



This article was previously published under Q142567



SUMMARY
In a one-to-many relationship, you can filter child records displayed in a grid by using the Value property of a combo box. One method is to use the RelationalExpr and LinkMaster properties of a grid. This article gives you another method, which uses a SET FILTER command along with a SELECT-SQL statement as the row source of a combo box.



MORE INFORMATION
To filter the records from the child grid, use the related field from the parent table as the RowSource of a combo box, and use the SET FILTER command.

Step-by-step Example
  Create a new form by typing the following command in the Command window: CREATE FORM.  Open the Data Environment, and add the Customer and Orders tables from the Testdata.dbc database located in the Vfp\Samples\Data subdirectory for Visual FoxPro 5.0 or home(2)+"data" for Visual FoxPro 6.0. From the Form menu, choose New Property, and in the Name box, type MVAR. Then click OK. Set the Properties window to the Form1 object. The MVAR property will be located at the bottom of the list on the All tab. Set the value of MVAR to "". This will initalize MVAR to a Character Data Type. Drag the Orders table to the form to create a grid. Change the name property of the grid to Grid1.  Place a combo box on the form after selecting it from the Form Controls toolbar. Type the following statement in the RowSource property for the combo box: SELECT CUST_ID FROM CUSTOMER INTO CURSOR TEMP  Choose 3-SQL Statement in the RowSourceType property.</li>  Open the Code window for the combo box, and add the following code to its InteractiveChange event: SELECT ORDERS THISFORM.MVAR=THIS.VALUE SET FILTER TO CUST_ID = THISFORM.MVAR GO TOP THISFORM.Grid1.RecordSource=THISFORM.Grid1.RecordSource </li> Save and run the form. When you select an item from the combo box, the grid should refresh and display the related child records.</li></ol>

NOTE: An index must exist on the filtered field from the child table to take advantage of the Rushmore technology.

Keywords: kbhowto KB142567

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.