Introduction to PowerBuilder

HomePrevious Lesson: Retrieve Only as Needed
Next Lesson: Error Handling

Prompt for Criteria

You have learned about allowing the user to do dynamic queries. Sometimes, you may want to restrict the fields that a user can query. Why would anyone want to restrict a query? Well, sometimes it may be for performance sake, such as, querying on a field might take time and hold the server resources or to stop querying on certain fields that doesn't make sense. In that situation, using Prompt for Criteria option is a good idea.

As you learned in the DataWindow painter, you can specify the fields to prompt the user for query criteria. If you haven't set it in the DataWindow painter and want to do it dynamically depending on certain conditions, you are welcome to do it. The following line sets prompt for criteria for "product_measurement_unit":
dw_product.Modify( &
 "product_measurement_unit.Criteria.Dialog=yes")

Till now we didn't use Modify() to change the column property. The above example shows how to use it. If you want the user to provide a value for the column in the Criteria dialog box, write:
dw_product.Modify( &
      "product_measurement_unit.Criteria.Required=yes")

Criteria dialog box uses the edit style painted in the DataWindow. If you want to override the edit style and allow the user to type the value in the criteria dialog box:
dw_product.Modify( &
    "product_measurement_unit.Criteria.Override_Edit=yes")

The above code overrides the edit style and displays a regular edit control box. This is specially useful when the edit style is DropDownListBox.

For practice, set few columns for criteria and run the application and set them back.
HomePrevious Lesson: Retrieve Only as Needed
Next Lesson: Error Handling