BBjStandardGrid::getRowModelIndexFromViewIndex

Description

In BBj 6.0 and higher, this BBjStandardGrid method maps the view index of a row to the model index.

Syntax

Return Value

Method

int

getRowModelIndexFromViewIndex(int index)

Parameters

Variable

Description

index

The index of a row as the user sees it.

Return Value

Returns the index of the row in the model that corresponds to the index of the row as the user sees it.

Remarks

If the grid is unsorted, this method returns the same value passed in.

Example

rem 'Get row view from model index

rem 'Obtain the instance of the BBjAPI object
let myAPI!=BBjAPI()

rem 'Open the SysGui device
SYSGUI=UNT
OPEN (SYSGUI) "X0"

rem 'Obtain the instance of the BBjSysGui object
let mySysGui!=myAPI!.getSysGui()

rem 'Set addWindow param values
X=10
Y=10
WIDTH=300
HEIGHT=300
TITLE$="BBj Window - Sort"

rem 'Set the current context
mySysGui!.setContext(0)

rem 'Create a window
myWindow! = mySysGui!.addWindow(X,Y,WIDTH,HEIGHT,TITLE$,$000002$)

rem 'Add a grid on the window
myGrid! = myWindow!.addGrid(101,25,25,250,200,$8060$,10,2)

rem 'Add button to the window
sortButton!=myWindow!.addButton(102,90,230,120,30,"Print Model Index",$$)

rem 'Set the grid properties
myGrid!.setDefaultColumnWidth(130)
myGrid!.setGridEditable(1)
myGrid!.setFitToGrid(1)
myGrid!.setRowHeight(16)
myGrid!.setEditable(1)
myGrid!.setHasColumnHeader(1)

rem 'Set the text for the column header
myGrid!.setColumnHeaderCellText(0,"Sort")

rem 'set the first column sortable by clicking on the Header
myGrid!.setColumnUserSortable(0,1)

rem 'Add text to the grid cells
FOR ROW = 0 TO 9
    FOR COL = 0 TO 1
        CELLTEXT$=STR(ROW+1) +" " + STR(COL+1)
        myGrid!.setCellText(ROW,COL,CELLTEXT$)
    NEXT COL
NEXT ROW

rem 'Sort the grid-descending by first column initially
myGrid!.sortByColumn(0,-1)

rem 'Register the CALLBACK routines
myGrid!.setCallback(myGrid!.ON_GRID_EDIT_STOP,"CALL_RESORT")
myWindow!.setCallback(myWindow!.ON_CLOSE,"APP_CLOSE")
sortButton!.setCallback(sortButton!.ON_BUTTON_PUSH,"MODEL_INDEX")

rem 'Process Events
process_events

rem 'Callback routine called when the user closes the application window
APP_CLOSE:
release

CALL_RESORT:
    PRINT "calling resort"
    myGrid!.resort()
return

MODEL_INDEX:
    PRINT "****ROW VIEW FROM MODEL INDEX****"
    FOR I = 0 to myGrid!.getNumRows()-1
        Print "The index of row # " + STR(I) + " as seen by the user is " + STR(myGrid!.getRowModelIndexFromViewIndex(I))
    NEXT I
    PRINT 'LF'
    PRINT "****ROW VIEW FROM INDEX MODEL****"
    FOR J = 0 to myGrid!.getNumRows()-1
        Print "The index of row # " + STR(J) + " as seen by the program is " + STR(myGrid!.getRowViewIndexFromModelIndex(J))
    NEXT J
    PRINT 'LF'
return

See Also

BBjAPI

BBjSysGui

BBjControl

BBjWindow

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.