The information in this article applies to:
SUMMARY
This article builds on Knowledge Base article Q192665 "HOWTO: Create a
Visual InterDev 1.0 Data Form Wizard with VI 6.0." The sample included in
this article assumes that you have created the sample found in article
Q192665.
Q192665 HOWTO: Create a Visual InterDev 1.0 Data Form Wizard with VI 6.0 MORE INFORMATION
In article Q192665, you built a Visual InterDev 6.0 version of the Visual
InterDev 1.0 Data Form Wizard using the Visual InterDev 6.0 Design-Time
Controls (DTCs). Using the DTCs, you were able to build a powerful
application in little time that required almost no code to be written by
hand. However, the application that was created did not possess the ability
to filter recordsets. Filtering gives the user the ability to reduce the
number of displayed records according to specified criteria (for example,
Name = 'Smith').
Before You BeginAs stated earlier, ensure that you have completed the application from Knowledge Base article Q192665 before continuing with this sample application. Since this article builds on that sample application, open the previously created application in Visual InterDev 6.0 before continuing.1) Add Filter Input FieldsIn order to provide input fields to allow the user to supply their filter parameters, you will add unbound input objects for each of your data-bound objects.Step 1: Locate your data-bound text fields and place the cursor after the first data-bound text field (txtProductCode). Double-click Textbox in the Toolbox to insert a new Textbox DTC. Right-click the inserted Textbox DTC and select Properties. Name the Textbox "txtFilterProductCode." Click OK. Repeat the process for both the txtProductName (txtFilterProductName) and txtUnitPrice (txtFilterUnitPrice) Textbox DTCs. Step 2: Place your cursor after the Listbox DTC (lstProductType) and double-click Listbox in the toolbar to insert a Listbox DTC. Right-click the Listbox DTC and select Properties. Name the Listbox "lstFilterProductType". Step 3: Select the Lookup tab and set the List Source to a Recordset with a Row source of rstProductType, a Bound column of ProductType, and a List field of ProductType. Click OK. It is important to note that the Listbox provided for filtering will be populated with the same list of items as the bound Listbox used in your Form View. Unfortunately, there is no option in the list to select "none"; that is, when you filter you will always select a ProductType to filter on. However, you will often want to exclude the ProductType from the filter. To remedy this, you need to provide a "blank" option for the filter Listbox. You have several choices for how to do this. For this sample, you will modify the recordset generated to include a blank row as the first option. Step 4: Right-click the Recordset DTC rstProductType and select Properties. Update the SQL Statement to the following then click OK:
Step 5: Locate the bound OptionGroup "optOnSale." Place your cursor after the OptionGroup and double-click OptionGroup in the Toolbox to insert an OptionGroup DTC. Right-click the new OptionGroup DTC and select Properties. Name the OptionGroup DTC "optFilterOnSale." The OptionGroup DTC has an issue similar to the ListBox DTC in that you need to provide a "blank" option to not filter on the OnSale field. You also need to consider the conversion of the values "true" and "false" to values that are valid for the filter. In this case, with an Access Database Yes/No field, true maps to -1 and "false maps to 0. Step 6: Select the Lookup tab. Set the List source to Static list with the following values in the list then click OK:
Save your changes. 2) Add Action ButtonsYou will be adding five new buttons to your page to enable the filtering capability:
Step 1: Place your cursor after the Requery button. Double-click Button in the Toolbox to add a Button DTC. Right-click the Button DTC and select Properties. Name the Button DTC "btnFilter" and set the Caption to "Filter." Click OK. Add three more Button DTCs with the following values:
Save your changes. 3) Create Persistent Filter PropertyIn order for your filter to continue to be applied while a user navigates the recordset, you need to ensure that it persists from page to page. You have several options to accomplish this. For this sample, you will use the PageObject DTC, which provides the capability to create a Property for the page. Once a Property is created, the PageObject DTC automatically creates getProperty() and setProperty() methods to enable us to set the property and retrieve it from page to page. For your sample application, you will create a property called "Filter." Once it is created, the PageObject will be expanded to have two new methods: getFilter() and setFilter().Step 1: Select the PageObject DTC, pageDFW. Right-click the PageObject DTC and select Properties. Click the Properties tab. Step 2: Enter a new property with the following values then click Close:
Now that you have a persistent filter property, you need to display the filter on the page for the user to see. To do this, you will expand the heading table to contain a second row, and you will ad a Label DTC to hold the filter value. Step 3: Locate the heading table (before the Grid DTC) and add the following Table Row HTML before the end table tag (</TABLE>).
Step 4: Drag a Label DTC into the first cell of this new table row. Right- click the Label DTC and select Properties. Name the Label DTC "lblCurrentFilter" and clear the default caption from the Field/expression field leaving it blank. Click the Format tab and select "Data contains HTML." Click OK. Save your changes. 4) Add Functions to Create Filter StatementAt this point, you will need to write a bit of code on your own; that is, without a DTC. The following is the VBScript code that you will use for your sample. You will create three subroutines for this purpose:
Insert the following code after "<SCRIPT ID=serverEventHandlersVBS LANGUAGE=vbscript RUNAT=Server>" in the heading of the page.
Save your changes. 5) Add Functions to Apply FilterYou need to add two functions to apply the filter: One that actually applies the filter and a second that ensures the filter will continue to be applied while the recordset is being navigated (using the onshow event of the PageObject). Here are the functions:
Add the following code after "<SCRIPT ID=serverEventHandlersVBS LANGUAGE=vbscript RUNAT=Server>" in the heading of the page:
6) Add Filter Mode to Form ManagerNow that you've added a number of new controls to the page, you need to create your Filter mode in the FormManager (fmgrDFW), as well as which controls will be available in Filter mode. You also need to update the FormView and ListView modes to hide the new controls, which will not be available to the user except in Filter mode.Step 1: Right-click the FormManager DTC (fmgrDFW) and select Properties. In the New mode field, type "Filter" and click ">" to add the Filter mode. Step 2: In the Form Mode section, select Filter. In the "Actions Performed For Mode" section, add the following:
Step 3: In the Form Mode section, select ListView. In the Actions Performed For Mode section, add the following to the list already there:
Step 4: In the Form Mode section, select FormView. In the "Actions Performed For Mode" section, add the following to the list already there:
Step 5: Select the Action tab and add the following to the current list:
Step 6: Select the row that has a Current Mode of Filter and an Object of btnApply. In the Actions Performed Before Transition section enter the following then click Close:
Step 7: Select the row that has a Current Mode of Filter and an Object of btnAllRecords. In the Actions Performed Before Transition section enter the following:
Repeat Step 7 for Current Mode of FormView and Object of btnAllRecords as well as for CurrentMode of ListView and Object of btnAllRecords. Click Close. Save your changes. You have now added filtering capability to your Data Form Wizard application. REFERENCES
For additional information, please see the following article in the
Microsoft Knowledge Base:
Q192665 HOWTO: Create a Visual InterDev 1.0 Data Form Wizard with VI
Keywords : kbVisID600 kbGrpASP |
Last Reviewed: May 4, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |