BBjDataBoundGrid::bindRecordSet

Description

In BBj 7.00 and higher, this method binds a BBjRecordSet to this BBjDataBoundGrid.

Syntax

Return Value

Method

void

bindRecordSet(BBjRecordSet recordset)

void

bindRecordSet(BBjRecordSet recordset, BBjVector fieldnames)

Parameters

Variable

Description

fieldnames

A list of names for the fields which should be bound to columns of the grid.

recordset

The recordset containing data.

Return Value

None.

Remarks

If fieldnames is not specified, all fields of the recordset will be bound to the grid.

If fieldnames is present, each element of fieldnames must be the name of a field within recordset.

Example

rem 'Data-bound controls with a Standard Navigator

rem 'Obtain the instance of the BBjAPI object
let api!=BBjAPI()
SYSGUI=UNT
OPEN (SYSGUI)"X0"
sysGui!=api!.getSysGui()

rem ' Create the data file
FILENAME$="State.dat"
MODES$=""
TEMPLATE$="STATE:C(2),NAME:C(16*=0)"
erase FILENAME$,err=*next
mkeyed FILENAME$,[0:1:2],0,32
channel=unt
open (channel)FILENAME$
dim REC$:TEMPLATE$

rem ' Load the file with state codes and names
while 1
    dread rec.state$,rec.name$,END=*break
    write record (channel)rec$
wend
close (channel)

rem ' Create the RecordSet
RecordSet! = BBJAPI().createFileRecordSet(FILENAME$,MODES$,TEMPLATE$)

rem 'Set addWindow param values
X=200
Y=200
WIDTH=350
HEIGHT=520
TITLE$="Data-bound controls sample"
sysGui!.setContext(0)
window! = sysGui!.addWindow(X,Y,WIDTH,HEIGHT,TITLE$,$00010002$)

rem 'add controls to window
window!.addStaticText(101,50,50,100,25,"State:")
state! = window!.addEditBox(201,100,50,40,25,"")
state!.setEditable(0)

window!.addStaticText(102,50,100,100,25,"Name:")
name! = window!.addEditBox(202,100,100,200,25,"")
Navigator! = window!.addNavigator(100,50,150,250,30,"Navigator")
button!=window!.addButton(300, 100, 200, 200, 40, "Delete current record")
button!.setCallback(button!.ON_BUTTON_PUSH, "buttonPush")
grid!=window!.addDataBoundGrid(301,50, 260, 250, 200)
grid!.setEditable(1)

rem 'bind controls to recordset
state!.bindRecordSet(RecordSet!,"state")
name!.bindRecordSet(RecordSet!,"name")
Navigator!.bindRecordSet(RecordSet!,"state")
grid!.bindRecordSet(recordSet!)
grid!.setDefaultColumnHeaders()

rem 'set callbacks
Navigator!.setCallback(Navigator!.ON_NAV_FIRST,"first")
Navigator!.setCallback(Navigator!.ON_NAV_PREVIOUS,"previous")
Navigator!.setCallback(Navigator!.ON_NAV_NEXT,"next")
Navigator!.setCallback(Navigator!.ON_NAV_LAST,"last")
window!.setCallback(window!.ON_CLOSE,"APP_CLOSE")
grid!.setCallback(grid!.ON_DB_GRID_ROW_CHANGE_REQUEST, "gridRowChange")
process_events

first:
    gosub save
    RecordSet!.first()
return

previous:
    gosub save
    RecordSet!.previous(err=*next)
return

next:
    gosub save
    RecordSet!.next(err=*next)
return

last:
    gosub save
    RecordSet!.last()
return

save:
    if (RecordSet!.isCurrentRecordDirty()) then
        print 'rb',
        RecordSet!.update(RecordSet!.getCurrentRecordData())
    endif
return

buttonPush:
    recordSet!.deleteCurrentRecordData()
    recordSet!.moveToRecord(0)
return

gridRowChange:
    event! = sysGui!.getLastEvent()
    print event!
    print event!.getRow(),",",event!.getColumn()
    recordSet!.moveToRecord(event!.getRow())
return

APP_CLOSE:
release
DATA "AK","Alaska"
DATA "AL","Alabama"
DATA "AR","Arkansas"
DATA "AZ","Arizona"
DATA "CA","California"
DATA "CO","Colorado"
DATA "CT","Connecticut"
DATA "DC","District of Columbia"
DATA "DE","Delaware"
DATA "FL","Florida"
DATA "GA","Georgia"
DATA "GU","Guam"
DATA "HI","Hawaii"
DATA "IA","Iowa"
DATA "ID","Idaho"
DATA "IL","Illinois"
DATA "IN","Indiana"
DATA "KS","Kansas"
DATA "KY","Kentucky"
DATA "LA","Louisiana"
DATA "MA","Massachusetts"
DATA "MD","Maryland"
DATA "ME","Maine"
DATA "MI","Michigan"
DATA "MN","Minnesota"
DATA "MO","Missouri"
DATA "MS","Mississippi"
DATA "MT","Montana"
DATA "NC","North Carolina"
DATA "ND","North Dakota"
DATA "NE","Nebraska"
DATA "NH","New Hampshire"
DATA "NJ","New Jersey"
DATA "NM","New Mexico"
DATA "NV","Nevada"
DATA "NY","New York"
DATA "OH","Ohio"
DATA "OK","Oklahoma"
DATA "OR","Oregon"
DATA "PA","Pennsylvania"
DATA "PR","Puerto Rico"
DATA "RI","Rhode Island"
DATA "SC","South Carolina"
DATA "SD","South Dakota"
DATA "TN","Tennessee"
DATA "TX","Texas"
DATA "UT","Utah"
DATA "VA","Virginia"
DATA "VI","Virgin Islands"
DATA "VT","Vermont"
DATA "WA","Washington"
DATA "WI","Wisconsin"
DATA "WV","West Virginia"
DATA "WY","Wyoming"
end

See Also

BBjSysGui

BBjControl

BBjWindow

BBjDataBoundGrid

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