Try OpenEdge Now
skip to main content
GUI for .NET Programming
Binding ABL Data to .NET Controls : Managing data updates : Handling user interface events : Finding the proper child query in a ProDataSet
 
Finding the proper child query in a ProDataSet
When a ProDataSet with data-relations binds with a ProBindingSource, the ProBindingSource creates and maintains a new child query for every expanded parent record in a hierarchical grid. So, for each child table, you are likely to have not a single query, but several different queries. The data-relation's CURRENT-QUERY( )method provides a way to find the child query that corresponds to the currently selected parent record. This attribute is useful when writing code to create, modify, or delete child records.
For example, take the GetCurrentQuery function, shown here:
FUNCTION GetCurrentQuery RETURNS HANDLE (INPUT cBufferName AS CHARACTER).
  DEFINE VAR hDataSet      AS HANDLE.
  DEFINE VAR hDataRelation AS HANDLE.
  DEFINE VAR hQuery        AS HANDLE.

  hDataSet = DATASET dsCustOrdOrdlines:HANDLE.
  IF cBufferName EQ "ttCustomer" THEN DO:
    hQuery = hTopQuery.
  END.

  ELSE IF cBufferName EQ "ttOrder" THEN DO:
    hDataRelation = hDataSet:GET-RELATION(1).
    hQuery = hDataRelation:CURRENT-QUERY().
  END.

  ELSE IF cBufferName EQ "ttOrderLine" THEN DO:
    hDataRelation = hDataSet:GET-RELATION(2).
    hQuery = hDataRelation:CURRENT-QUERY().
  END.

  ELSE
    hQuery = ?.

  RETURN hQuery.

END FUNCTION.
You pass in a buffer name and the function matches the name to one of the tables in the dsCustOrdOrdlines ProDataSet. If the buffer is one of the child tables, the function uses the CURRENT-QUERY( ) method to find the appropriate query and passes it back. For an example of this technique, see UpdatableDataBindingGrid.p (Part 4 of 11) in the Internalprocedures and functions.
If the ProDataSet has a recursive data-relation, it presents an additional level of complexity. Because of the recursive data-relation, a single buffer name might be associated with several different bands in a hierarchical control. A band consists of all the records at a given level in the hierarchical display. This makes the buffer name insufficient to access the correct query.
To handle recursive data-relations, you must specify the optional BandIndex parameter when using the CURRENT-QUERY( ) method. The BandIndex property indicates which level of the hierarchical display contains the currently selected record. Using the BandIndex, the CURRENT-QUERY( ) method can determine which query corresponds to the focused row in that band.
Note: The BandIndex is a 0-based index.
The following procedure is a CreateRow event handler designed to handle a ProDataSet with a recursive data-relation. First, it checks to see if the BandIndex is 0, which always uses the top query. If not, it uses the BandIndex as the parameter for the CURRENT-QUERY( ) method to find the handle of the query that corresponds to the focused row in that band.
PROCEDURE recursiveRelationCreateRow:

DEFINE INPUT PARAMETER sender AS System.Object.
DEFINE INPUT PARAMETER args   AS Progress.Data.CreateRowEventArgs.

DEFINE VARIABLE hBuffer AS HANDLE.
DEFINE VARIABLE hQuery  AS HANDLE.

hBuffer = args:BufferHdl.
IF args:BandIndex EQ 0 THEN
hQuery = hTopQuery.
ELSE
hQuery = hRelation:CURRENT-QUERY(args:BandIndex).

hBuffer:BUFFER-CREATE().
hQuery:CREATE-RESULT-LIST-ENTRY().
args:Created = TRUE.

END.