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

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