CGXBrowserGrid::AddNew
virtual ROWCOL AddNew();
throw( CNotSupportedException );
Return Value
Returns the row id of the new row.
Remarks
Prepares the grid for adding a new record. The grid appends a new line in the grid. AddNew changes the grid context into append-mode. Subsequent changes with StoreStyleRowCol in the last row will be stored in the current record buffer. This buffer will be flushed the next time Update is called.
If you want to add records programmatically, you should call AddNew before changing the cells in appended row and call Update to complete the addition. See also the example.
You can cancel the append-mode with UndoRecord.
If CanAppend returns FALSE, a CNotSupportedException will be thrown.
Example
The following sample code shows you how you can programmatically append a record to your data source.
// Append a row to the grid
if (CanAppend())
{
// Add a row
ROWCOL nAppendRow = AddNew();
ASSERT(nAppendRow != GX_INVALID);
// Lock updating the grid
BOOL bLock = LockUpdate(TRUE);
// Change cells in new row
SetValueRange(CGXRange(nAppendRow, 1), "1");
SetValueRange(CGXRange(nAppendRow, 2), "2");
// Unlock painting
LockUpdate(bLock);
// Flush pending changes, Update will also redraw
// the row.
Update();
}
Please note that this code depends only on CGXBrowserGrid-functionality and thus makes appending rows independent from your specific data source. You can use the same code for appending a row to a DAO recordset, ODBC recordset or any other external data source.
See Also
CGXBrowserGrid::Update CGXBrowserGrid::UndoRecord CGXBrowserGrid::CanAppend