Tech Articles


Dynamic Runtime DataWindow Group Creation


Here’s a DataWindow tip…and a half.

Unless you want to dynamically build a DataWindow object from scratch at runtime (it’s do-able…but quite involved), there’s no direct way to create a group for a DataWindow object in an ad hoc manner. Here’s a workaround.

First, insert a computed field in an extant DataWindow object and give it an expression that’s an empty string. For the sake of this tip the computed field’s name will be “dynamicgroup”.

image

 

 

 

 

 

 

 

 

Then create a group based on this computed field.

Image

 

 

 

 

 

 

 

 

 

 

image

 

 

 

 

 

 

 

Format the DataWindow object according to your needs and save.

Now at runtime, modify the computed field’s expression to have the value of the column name by which you wish to group the result set.

dw_employees.setredraw( FALSE )

dw_employees.Modify(“dynamicgroup.Expression='” + as_coltogroup + “‘” )

dw_employees.setsort( as_coltogroup + ” A”)

dw_employees.sort( )

dw_employees.groupcalc( )

dw_employees.setredraw( TRUE )

After calling SetSort() and Sort() to sort by the column on which you’re grouping, don’t forget to call GroupCalc() to recalculate the breaks in the groupings.

Certainly this technique may be adapted to implement more than one grouping level. For those of you who maintain and enhance frameworks, the sample code fragment can certainly be made more generic as far as the reference to the DataWindow control and to the name of the computed field(s).

OK, here’s the half (.5) tip.

You’ve defaulted the value of the computed field’s expression to an empty string. This will work fine for grouping on columns of type string. However, for columns of other data types, you’ll need to invoke the DataWindow expression function String() to convert the non-string columns’ values to strings in order for the runtime modification to have the desired effect. Here’s how the accommodation appears in the sample code from earlier in this tip…

dw_employees.Modify(“dynamicgroup.Expression=’String(” + as_coltogroup + “)'” )

Comments (0)
There are no comments posted here yet

Find Articles by Tag

UI GhostScript SnapDevelop SqlExecutor Database Table Schema Resize Database Object PBDOM HTTPClient Jenkins OrcaScript SDK RibbonBar Elevate Conference InfoMaker TLS/SSL PBVM JSON SQL Server Encryption Authentication JSONGenerator Repository Validation PowerBuilder Database Table CrypterObject PowerServer Web Export JSON DataWindow JSON External Functions Windows OS 64-bit Design Configuration JSONParser PBNI 32-bit Array Interface Text PDF NativePDF Sort Database Table Data IDE Graph DLL Database Windows 10 Icons Deployment Window CoderObject PostgreSQL ODBC driver Import ODBC SnapObjects Event Handling Open Source Import JSON CI/CD Database Profile File Authorization Debug Service SQL Installation Encoding WebBrowser Model Filter Excel SVN Transaction Migration RibbonBar Builder Error OAuth Source Code SqlModelMapper Charts UI Themes Branch & Merge COM Expression PDFlib Linux OS .NET Std Framework Database Connection RichTextEdit Control Messagging PowerBuilder (Appeon) REST Web API Export Event PFC Variable Automated Testing XML Icon Debugger .NET Assembly PowerBuilder Compiler C# MessageBox Performance BLOB TortoiseGit Source Control Script Trial OAuth 2.0 Menu Oracle Mobile Web Service Proxy WinAPI Application UI Modernization API TreeView Outlook Azure PostgreSQL Git Stored Procedure Database Painter License Event Handler Data Testing OLE DragDrop .NET DataStore Android Debugging DataWindow PowerScript (PS) ActiveX RESTClient iOS PowerServer Mobile DevOps Visual Studio Syntax TFS DataType Bug SOAP Platform Class