Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

DataGridView: paginated grids

DataGridView shows a list of rows from a table on a Screen, with native pagination (Page Up/Down) over a DDS subfile. There can only be one per Screen.

1. Full example

@Properties {
    Type : Screen
    Name : SGRIDDEMO
}
@References {
    Tables = ["tables/TLGRIDDEMO.warp"]
}
@Variables {
    global {
        VCustCode char(6)
        VName     char(20)
        VCity     char(15)
        VTotal    number(5)
        VLast     char(6)
    }
}
@Layout {
    DataGridView("GridDemo", 2, 2, 5)
    [
        Column("Code", &VCustCode)
        Column("Name", &VName)
        Column("City", &VCity)
    ]
}
@Source {
    Event Load
        For Each In GRIDDEMO Index GRIDDMNOM
            &VCustCode = CustCode
            &VName     = Name
            &VCity     = City
            LoadRow()
        EndFor
    EndEvent

    Event Enter
        &VTotal = 0
        For Each Row
            &VTotal = &VTotal + 1
            &VLast = &VCustCode
        EndFor
        Message("Rows: " + String(&VTotal, 5) + " Last: " + &VLast, Info)
    EndEvent
}

2. Loading the grid: Event Load + LoadRow()

LoadRow() takes the current values of the variables bound to each Column and appends a row to the grid. It’s only valid inside a For Each in the body of Event Load (that For Each must declare Index). It loads the entire result set in a single pass — Page Up/Down are native terminal scrolling over what’s already loaded; Load never runs again.

3. Reading the selection: RefreshSelectRow() and CurrentInput()

When the cursor lands inside the grid’s rectangle (header, attention row, or any data row), CurrentInput() returns the grid’s name. RefreshSelectRow() re-reads the row under the cursor and writes each column (including Hidden ones) back into its bound variable — it’s the reverse of LoadRow():

Event Enter
    &Control = CurrentInput()
    If &Control = "GridDemo"
        RefreshSelectRow()
        Message("You selected: " + &VCustCode, Info)
    EndIf
EndEvent

4. Iterating over all loaded rows: For Each Row

For Each Row ... EndFor iterates over all rows already loaded into the subfile (not the database table), writing each Column into its bound variable before every iteration — same direction as RefreshSelectRow(). It doesn’t support Index/Where/When None because there’s no table being iterated:

Event Enter
    &VTotal = 0
    For Each Row
        &VTotal = &VTotal + 1
    EndFor
EndEvent

5. Hidden columns

Column("Internal ID", &VInternalId, Hidden)

A Hidden column loads its data (participates in LoadRow()/RefreshSelectRow()/For Each Row) but doesn’t show its cell or header title — useful for carrying an internal key without taking up screen space.

6. Editable columns (Input)

Column("Quantity", &VQuantity, Input)

Lets the user edit the value directly in the grid.

7. Rules to keep in mind

  • The name ("GridDemo") is required and must be unique among Input/DataGridView controls on the same screen.
  • Only one DataGridView per Screen.
  • Only valid inside a Screen’s @Layout, never a Program’s.