Author: | Eric Aling |
Accessed: |
With PowerBuilder, it is not possible to change groups dynamically during runtime. It would be nice if you could do that using the modify() function or with the direct syntax called dot notation. However, there is a slick trick for doing this. This is how:
First, create a computed field in the detail band and call it for instance cf_group. As expression, use "" (empty string) or other initial value you want to group on ( a field or combination of fields can also be used). Now, create a group, based on this computed field. Save the datawindow. At runtime, we can change the expression of the computed field using the modify() function like:
dw_1.Modify("cf_group.expression='field1' ")
With this modify() statement, the group is now based on field1. Then, there are some culprits: one is that the sortorder must be the same as the grouping. Now, you can solve this simply by sorting on the cf_group field or set a new sortorder using the setsort() and sort() functions. Secondly, don't forget to call the CalcGroup() function to recalculate all the other computed fields after you've changed the cf_group field.
Hi Eric. I had to make one small change to this tip to make it work in PB
6.5. PB refuses to do a proper Modify when the computed column contains a
string (like the empty string '"') and the column to be grouped on is of a
different data type (like a long or a date). You have to change the
computed column expression to add a string function. Little snippet of
code:
For li_x = 1 To UpperBound(as_groupcols)
ls_groupcol = "groupcol_" + String(li_x)
If Lower(Left(idw_requestor.Describe(as_groupcols[li_x] + ".ColType"), 4))
= "char" Then
ls_modexp = ls_groupcol + ".expression='" + as_groupcols[li_x] + "'"
Else
ls_modexp = ls_groupcol + ".expression='String(" + as_groupcols[li_x] +
")'"
End If
--
Neil Negandhi
negandhi@vex..net