BBjDataBoundGrid

Description

In BBj 7.0 and higher, the BBjDataBoundGrid is a grid that can be bound to a BBjRecordSet. The selected row of the BBjDataBoundGrid is always the current record of its bound BBjRecordSet. Changes of the values in the BBjRecordSet are reflected in the BBjDataBoundGrid and edits that occur in the selected row of the BBjDataBoundGrid are reflected as changes in the current record of the BBjRecordSet. BBjDataBoundGrid extends the class BBjGrid.

Implemented Interfaces

CommonGrid, Focusable, MouseWheelEnabled, SimpleRecordSetBindable,TabTraversable

Creation

BBjAPI > BBjSysGui > BBjWindow > BBjDataBoundGrid

A BBjDataBoundGrid object is created through the following BBjWindow method:

Return Value

Method

BBjDataBoundGrid

addDataBoundGrid(int ID, number x, number y, number width, number height)

BBjDataBoundGrid

addDataBoundGrid(int ID, number x, number y, number width, number height, string flags)

Methods of BBjDataBoundGrid

Return Value

Method

void

bindRecordSet(BBjRecordSet recordset)

void

bindRecordSet(BBjRecordSet recordset, BBjVector fieldnames)

BBjVector

getBoundFieldNames()

void

setDefaultColumnHeaders()

Methods of BBjDataBoundGrid inherited from BBjGrid

Methods of BBjDataBoundGrid inherited from BBjControl

Methods of BBjDataBoundGrid implemented for CommonGrid

Return Value

Method

void

endEdit()

void

endEdit(int suppress)

int

getColumnStyle(int column)

int

getDefaultGridStyle()

void

setColumnStyle(int column, int style)

void

setDefaultGridStyle(int style)

void

startEdit(int row, int col)

Methods of BBjDataBoundGrid implemented for Focusable

Return Value Method
boolean isFocusable()
void setFocusable(boolean focus)

Methods of BBjDataBoundGrid implemented for MouseWheelEnabled

Return Value Method
int getScrollWheelBehavior()
void setScrollWheelBehavior(int trav)

Methods of BBjDataBoundGrid implemented for SimpleRecordSetBindable

Return Value Method
BBjRecordSet getBoundRecordSet()
void unbindRecordSet()

Methods of BBjDataBoundGrid implemented for TabTraversable

Return Value Method
boolean isTabTraversable()
void setTabTraversable(boolean trav)

Events

Callback Code

Object-oriented Event

Read Record Event

Code

ON_DB_GRID_ROW_CHANGE_REQUEST

BBjDBGridRowChangeRequestEvent

N/A

x

Remarks

BBjDataBoundGrid also generates all the events of a BBjGrid except ON_GRID_HIT_BOTTOM, ON_GRID_HIT_TOP, ON_GRID_TOP_ROW_CHANGE, and ON_GRID_UPDATE.

Clicking in a cell that is not in the currently selected row the BBjDataBoundGrid will generate a DBGridRowChangeRequestEvent but it will not change the currently selected row. The program must examine the DBGridRowChangeRequestEvent and call the method BBjRecordSet::moveToRecord() to change the current record of the BBjRecordSet. Changing the current record of the BBjRecordSet will cause the selected row of the BBjDBGrid to change.

Example

rem 'This DataBoundGrid example uses

sysgui=unt
open (sysgui)"X0"
sg!=BBjAPI().getSysGui()
win! = sg!.addWindow(50, 50,505,441,"DataBound controls")

navigator!=win!.addNavigator(100,10,5,230,20,"")
custNumLabel!=win!.addStaticText(101,10,30,100,20,"custNum")
custNum!=win!.addInputE(102,10,30,100,20,"")
f irstNameLabel!=win!.addStaticText(103,10,550,100,20,"firstName")
firstName!=win!.addInputE(104,110,55,130,20,"")
date! = win!.addInputD(222,110,80,130,20)
lastNameLabel!=win!.addStaticText(105,260,30,100,20,"lastName")
lastName!=win!.addInputE(106,360,30,130,20,"")
companyLabel!=win!.addStaticText(107,260,55,100,20,"company")
company!=win!.addInputE(108,360,55,130,20,"")
grid!=win!.addDataBoundGrid(109,10,105,400,300)

connect$="jdbc:basis:localhost:2001?database=ChileCompany&user=admin&password=admin123"
mode$=""
select$="select cust_num,first_name,last_name, company,last_purch_date from Customer"
recordSet!=BBjAPI().createSQLRecordSet(connect$,mode$,select$)

navigator!.bindRecordSet(recordSet!, "cust_num")
custNum!.bindRecordSet(recordSet!, "cust_num")
firstName!.bindRecordSet(recordSet!, "first_name")
date!.bindRecordSet(recordSet!,"last_purch_date")
lastName!.bindRecordSet(recordSet!, "last_name")
company!.bindRecordSet(recordSet!,"company")
grid!.bindRecordSet(recordSet!)
grid!.setDefaultColumnHeaders()
grid!.setRowHeight(20)
grid!.setFitToGrid(4)
grid!.setEditable(1)
grid!.setTabAction(grid!.GRID_NAVIGATE_GRID)

rem 'in the database the field last_purch_date is a numberic value representing a julian date
rem 'by default, the dbGrid will display the number.  If we want to see it as a date we must
rem 'set the column style and the mask
grid!.setColumnStyle(4, bbjapi().getSysGui().GRID_STYLE_INPUTD)
grid!.setColumnMask(4,"%Mz/%Dz/%Yz")
navigator!.setCallback(navigator!.ON_NAV_FIRST, "navFirst")
navigator!.setCallback(navigator!.ON_NAV_PREVIOUS, "navPrevious")
navigator!.setCallback(navigator!.ON_NAV_NEXT, "navNext")
navigator!.setCallback(navigator!.ON_NAV_LAST, "navLast")
win!.setCallback(win!.ON_CLOSE, "CloseWindow")
grid!.setCallback(grid!.ON_DB_GRID_ROW_CHANGE_REQUEST, "navGrid")

process_events

navFirst:
    gosub updateRecord
    recordSet!.first()
return

navPrevious:
    gosub updateRecord
    recordSet!.previous()
return

navNext:
    gosub updateRecord
    recordSet!.next()
return

navLast:
    gosub updateRecord
    recordSet!.last()
return

navGrid:
    gosub updateRecord
    event!=sg!.getLastEvent()
    row=event!.getRow()
    recordSet!.moveToRecord(row)
    grid!.setSelectedColumn(event!.getColumn())
return

updateRecord:
    if (recordSet!.isCurrentRecordDirty())
        recordSet!.update(recordSet!.getCurrentRecordData())
    endif
return

CloseWindow:
release

See Also

BBjGrid

BBjStandardGrid

BBjDataAwareGrid

BBjAPI()

BBj Object Variables

BBj Object Assignment

BBj Object Error Handling

BBj Object Operators

CALLBACK Verb - Register BBj Subroutine

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