| | | | Browse by category |
Problem
How can I programmatically append a record to the data source?
Cause
Action
The following sample code shows you how you can programmatically append a record to your data source.
Example:
// Append a row to the grid if (CanAppend()) { |
||
// Add a row ROWCOL nAppendRow = AddNew(); ASSERT(nAppendRow != GX_INVALID); // Lock updating the grid // Change cells in new row // Unlock painting // Flush pending changes, Update will |
||
} |
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 ADO recordset, ODBC recordset or any other external data source.
Attention!
You have to change fields, so that the record will be set dirty. Otherwise, the call to Update() will undo the AddNew() command.
The following sample shows an alternative that allows you to add a record directly to a ADO recordset and bypass the grid. This should work similar for ODBC.
AdoRecordset* prs = OnGetRecordset(); prs->AddNew(); prs->SetFieldValue(0, "2"); prs->Update(); // Now, call OnAddedNewRecord so that the grid // Scroll to the last row |