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

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