The value to be added to the data source for this column.
Function InitialValue Returns String
| Call: | Get InitialValue to StringVariable |
InitialValue is called any time a new row is created and is used to provide a value for the datasource. It is used used for different purposes in cCJGrids and cDbCJGrids.
When a new row is created, the datasource object calls CreateDataSourceRow. This message sends the InitialValue message each grid column object and places the returned value into the grid. By default, this returns blank. With simple grids, CreateDataSourceRow is primarily called when new rows are being created and not when the datasource is being initially filled. Therefore, you can use InitialValue to provide an initial value for a newly inserted or appended row.
Function InitialValue Returns String
Function_Return "New Name"
End_Function
In some cases, you might actually use CreateDataSourceRow to populate your grid. In this case, InitialValue is called for each row added. If you are binding your grid data in a data buffer, this can be used to provide data binding in each column. Assume you are loading your data as follows:
Procedure LoadData
Handle hoDataSource
Boolean bFound
tDataSourceRow[] TheData
Integer iRows iFile
Integer iNum iName iState iZip iStatus
Get phoDataSource to hoDataSource
Clear Customer
Find ge Customer by Index.1
Move (Found) to bFound
While bFound
If (Customer.Status="Y") Begin
// creates a datasourcerow based on current buffer data
Get CreateDataSourceRow of hoDataSource to TheData[iRows]
Increment iRows
End
Find gt Customer by Index.1
Move (Found) to bFound
Loop
Send InitializeData TheData
Send MovetoFirstRow
End_Procedure
Each time CreateDataSourceRow is called, each column will receive the InitialColumn message. Since this is being called with the proper record data in your record buffer, you can bind you data as follows:
Object oCustomer_Name is a cCJGridColumn
Set piWidth to 231
Set psCaption to "Customer Name"
Function InitialValue Returns String
Function_Return Customer.Name
End_Function
End_Object
If you were using this same logic to insert rows, you'd need to a way to distinguish between initializing rows and adding rows. This could be done in various ways. You could create and set status properties or could make sure the global buffer is cleared before you do an insert.
Data-aware grids use InitialValue to manage the binding between your data dictionaries and the grid. The Entry_Item command sets the piBindingTable and piBindingColumn properties and those properties are used by InitalValue to move data from a table.column to the datasource. This process occurs all the time and not just when you are loading your data. Each time a row is refreshed, InitialValue is called. Therefore, you will usually not augment InitialValue in data aware grids.
When InitialValue is called for a column that is not bound to a table (piBindingTable=0), it considers this column to be a calculated column and it sends the event OnSetCalculatedValue to obtain a calculated column value. This event should be used for augmentation.