Skip to content

CanAddRow - cCJGrid

Called before any row addition. Returns True if a row can be inserted or appended.

Type: Function
Return Data Type: Boolean

Syntax

Function CanAddRow Returns Boolean

Call Example

Get CanAddRow to BooleanVariable

Description

The CanAddRow function is called before a row is about to be added via insertion or append. If the function returns False, the row will not be added. This is used in addition to the pbAllowInsertRow and pbAllowAppendRow properties. In other words, pbAllowInsertRow and pbAllowAppendRow are tested before CanAddRow is called. If the grid's pbReadOnly property is True, CanAddRow will return false. In addition, when CanAddRow is called, it calls CanAddRow in the datasource object. This allows the datasource object to control if a row can be added. For example, if the cDbCJGridDataSource object's data-dictionary is read-only, it will not allow row additions.

Augmenting CanAddRow can be particularly useful to controls adding rows based on the current condition of a view and its data. For example, this augmentation would disallow adding rows in a header / detail grid if the header record is new and unchanged. This would allow you to enter the grid, but you would not be able to make any changes in the empty grid.

Function CanAddRow Returns Boolean
    Boolean bChanged bRec bCanDo
    Handle hoServer

    Forward Get CanAddRow to bCanDo
    If bCanDo Begin
        // get the DD of the header 
        Delegate Get Server to hoServer
        Get Should_Save of hoServer to bChanged
        Get HasRecord of hoServer to bRec
        // We allow new rows if the header  record exists or
        //  it is changed, indicating that there is something to save
        Function_Return (bChanged or bRec)
    End
End_Function

User interface actions, such as message boxes, may not be used in this function.

See Also

CanSaveRow | CanDeleteRow | CanEditColumn

Return Value

Returns True if a row can be inserted or appended. If the function returns False, the row will not be added.