Consultor Eletrônico



Kbase P162529: How to populate an UltraGrid based on other controls in a GUI for .NET form
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   07/05/2010
Status: Unverified

GOAL:

How to populate an UltraGrid based on other controls in a GUI for .NET form

GOAL:

How to filter rows in an UltraGrid with a query

FACT(s) (Environment):

Windows
OpenEdge 10.2x

FIX:

The UltraGrid has extensive built-in capabilities for filtering rows bases on user input. However, depending on application requirements it might be desirable to filter the rows based on input from other controls on a form. The following example shows how to use a basic query on the Sports2000 Customer table to fill an UltraGrid, and then add on to that query to filter certain rows based on the input into a TextBox control. The Validated event of the text box is used to add a filter to the query based on the contents of the TextBox. Although only one additional control is used here, a query could be built up using input to multiple controls, providing maximum flexibility to the application designer.
/*
Put the initial Customer query in a variable. Use a WHERE clause
that is always true. This will facilitate adding additional
filters to the WHERE clause based on user input.
*/
DEFINE VARIABLE cBaseCustomerPrepareString AS CHARACTER NO-UNDO
INITIAL 'PRESELECT EACH Customer WHERE 0=0 '.
...
/*
Do the initial population of the grid in the constructor.
The binding source makes it easy to keep the values displayed by
the UltraGrid in sync with the underlying data.
*/
CREATE QUERY hCustomerQuery.
hCustomerQuery:SET-BUFFERS(BUFFER Customer:HANDLE).
hCustomerQuery:QUERY-PREPARE(cBaseCustomerPrepareString).
hCustomerQuery:QUERY-OPEN.
bindingSourceCustomer:handle = hCustomerQuery.
...
/*
When the Validated event for the TextBoxCountry TextBox is
fired, add on to the WHERE clause based on the information entered.
*/
METHOD PRIVATE VOID textBoxCountry_Validated(
INPUT sender AS System.Object, INPUT e AS System.EventArgs ):

DEFINE VARIABLE cFilteredPrepareString AS CHARACTER NO-UNDO.

cFilteredPrepareString = cBaseCustomerPrepareString + " AND Country = "
+ QUOTER(TextBoxCountry:Text).

/*
Prepare and re-open the query. The UltraGrid will now display only
the customers in the country specified.
*/
hCustomerQuery:QUERY-PREPARE(cFilteredPrepareString).
hCustomerQuery:QUERY-OPEN().

RETURN.

END METHOD.