Microsoft KB Archive/139348

= How To Set a Filter Using an Item Selected from a Combo Box =

Article ID: 139348

Article Last Modified on 8/30/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q139348



SUMMARY
This article shows by example how to use the item selected in a combo box to filter what is displayed in a second combo box.



The Scenario
Say you have two combo boxes on a form. The first reflects a field in the parent table, and the second reflects the child records related to the parent value picked from the possible parent values presented in the first combo box.

Step-by-Step Procedure
 Create a new form. Right-click the form, and click Data Environment. Then right-click the Data Environment window, and add the Customer table from \Vfp\Samples\Data. In Visual FoxPro 6.0 the Customer table can be found in home(2)+"data". Right-click the Data Environment window again, and add the Orders table from \Vfp\Samples\Data. In Visual FoxPro 6.0 the Orders table can be found in home(2)+"data". Place a combo box on the form. Change its RowSource property to Customer.cust_id and its RowSourceType property to 6 - Fields. Add the following code to the InteractiveChange event for the combo box:

thisform.dataenvironment.cursor2.filter= ; "alltrim(cust_id)='"+alltrim(this.value)+"'"

 Place a second combo box on the form. Change its RowSource property to Orders.to_name and its RowSourceType property to 6 - Fields. Save and run the form.</li> Select a customer ID from the first combo box. Click the down arrow on the second combo box, and note the records displayed in the second combo box relates to the customer ID you selected from the first combo box.</li></ol>

NOTE: If you place the line of code in Step 5 in the Valid event for the combo box, the event fires twice - once when you select an item from the combo box and again when the combo box loses the focus. Placing the code in the InteractiveChange event avoids this behavior.

Keywords: kbhowto KB139348

-

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

© Microsoft Corporation. All rights reserved.