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