Tech Articles


Grid datawindow object with variable number of columns


Here is a way to build a grid datawindow which contains columns corresponding to an unknown number of data elements. You could use this approach in creating a project schedule, inventory location system, baseball box score, or any number of other examples. My example assumes the minimum number of columns to be four.

This create grid event returns a string.

long    ll_columns, ll_count, ll_pos
string ls_errors, ls_sql, ls_dw_presentation, ls_dw_syntax, ls_find, ls_name, ls_mod_string
// base presentation information
ls_dw_presentation =    "style( type=Grid                          &
            Horizontal_spread = 25 )            &
     datawindow( units=1                       &
             Color= 16777215)              &
     column( Font.Face='Arial'         &
         Font.Height=-9                    &
         Font.Weight=400)                  &
         text(   Font.Face='Arial' &
         Font.Height=-9                    &
         Font.Weight=400                   &
             Border=6)"

// set initial grid to 4 columns (plus time_of_day and last_col columns)
ls_sql = "SELECT space(10) as time_of_day, space(40) as col1, space(40) as col2, space(40) as col3, space(40) as col4,"

ll_count = 5 // next column to add would be 5

// this is the variable number of data elements
ll_columns = ids_trains.rowcount()

// add any additional columns past 4
DO WHILE ll_count <= ll_columns
    ls_sql += " space(40) as col" + string(ll_count) + ","
    ll_count++
LOOP

ls_sql += " '' as last_col"
ls_sql += " FROM dbo.TRAINS WITH (NOLOCK) WHERE 1 = 2"
// build the datawindow syntax from the presentation and sql statement
ls_dw_syntax = SQLCA.Syntaxfromsql( ls_sql, ls_dw_presentation, ls_errors)
IF Len(ls_errors) = 0 THEN
    // widen the header band a bit
    ls_dw_syntax = Replace(ls_dw_syntax, Pos(ls_dw_syntax,"header(height=19)"), Len("header(height=19)"), "header(height=23)")
    // create dwo and assign to grid
    dw_grid.create(ls_dw_syntax,ls_errors)
END IF
// appearance modifies
dw_grid.modify("last_col.visible=FALSE")

FOR ll_count = 1 TO Long(dw_grid.Object.DataWindow.Column.Count)
    IF dw_grid.Describe("#" + String(ll_count) + ".Visible") = "1" Then
        ls_name = dw_grid.Describe("#" + String(ll_count) + ".Name") 
        ls_mod_string = ls_name + "_t.background.mode=0" // must set to opaque or color does not show
        ls_errors = dw_grid.modify(ls_mod_string)
        // set the column heading color
        ls_mod_string = ls_name + "_t.background.color=12632256"
        ls_errors = dw_grid.modify(ls_mod_string)
        IF POS(ls_name ,'time_of_day') = 0 THEN
            ls_mod_string = ls_name + "_t.Alignment=0" //left
            ls_errors = dw_grid.modify(ls_mod_string)
        END IF
        ls_mod_string = ls_name + "_t.Height=18"
        ls_errors = dw_grid.modify(ls_mod_string)
        ls_mod_string = ls_name + "_t.tooltip.enabled=1"
        ls_errors = dw_grid.modify(ls_mod_string)
    END IF
NEXT
RETURN ls_errors


Now I know you can do several modifies with a single statement but it is much easier to debug if you do a single attribute at a time.

Once you have the grid set up you can call subsequent methods to populate it (and make columns invisible if needed), resize the width of the columns, etc.

Example schedule grid datawindow


Example grid for a time schedule with fifteen minute increments.

Comments (0)
There are no comments posted here yet

Find Articles by Tag

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