< Day Day Up > |
In Visual FoxPro, the SET FILTER command provides one mechanism for viewing only certain records. To use it, define the parameters for selecting filter values and issue the command. To show how little code is required to filter records in Visual FoxPro, I built the form shown in Figure 9.1. The grid's ReadOnly property is set to .T. and the DeleteMark property is set to .F. . Figure 9.1. A simple filtering form.The code for the form is located in four places, as shown in Listing 9.1. Listing 9.1. Code for the Visual FoxPro Order Filtering FormForm Load event: SELECT Orders SET FIELDS TO OrderID, ShipName, ShipCity, ShipCountr Form Init event THISFORM.Combo1.SetFocus cmdClose Click event THISFORM.Release Combobox1 InteractiveChange event SELECT Orders SET FILTER TO ( ShipCountr = THISFORM.Combo1.Value ) THISFORM.Grid1.Refresh GO TOP The RecordSource for the Grid is Orders , and the RecordSource for the ComboBox is Countries . The InteractiveChange event of the ComboBox allows us to apply the filter and display only the records that meet the filtering criteria. The Init event sets the focus to the ComboBox so that the user is made aware of the filtering mechanism as soon as the form instantiates. Some aspects of data handling are so much easier in FoxPro than they are in any other language that we've become a little spoiled. For example, the form's Data Environment opens the tables, then closes them when the form is closed. The SET FIELDS command in FoxPro limits the fields displayed to the four named fields. This form shows how powerful FoxPro's SET commands are. As we'll see shortly, there are no SET commands in Visual Basic .NET, so all data management has to be done individually on each dataset or data view. |
< Day Day Up > |