Objective Grid: Appending a record to the data source

Article ID: 334
Last updated: 07 Jun, 2018
Article ID: 334
Last updated: 07 Jun, 2018
Revision: 3
Views: 1855
Posted: 24 Jan, 2001
by Meltreger B.
Updated: 07 Jun, 2018
by Meltreger B.

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
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 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
// gets informed that a record has been added.
OnAddedNewRecord();

// Scroll to the last row
MoveCurrentCell(GX_BOTTOM);
MoveCurrentCell(GX_LEFT);

This article was:   Helpful | Not helpful
Report an issue
Article ID: 334
Last updated: 07 Jun, 2018
Revision: 3
Views: 1855
Posted: 24 Jan, 2001 by Meltreger B.
Updated: 07 Jun, 2018 by Meltreger B.

Others in this category