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

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