CGXGridCore::TransferCurrentCell
virtual BOOL TransferCurrentCell(BOOL bSaveAndValidate = TRUE, UINT flags = GX_UPDATENOW, BOOL bCreateHint = TRUE);
bSaveAndValidate
pecifies whether the current cell’s contents shall be stored or if the current cell should be reinitialized. If TRUE, current cell’s contents will be stored and the current cell will be deactivated. If FALSE, the the current cell’s content is reset and the cell is reinitialized.
flags
This parameter will be passed as flags attribute to SetCurrentCell. The following flags can be composed:
- GX_INVALIDATEonly invalidates the window.
- GX_SMARTwindow is updated after deactivating the cell; the new cell is only invalidated (UpdateWindow() is not called) and the redrawing will be delayed until the grid receives a WM_PAINT message.
- GX_UPDATENOWis the most efficient update technique to position the cell.
- GX_SCROLLINVIEWspecifies that the current cell should scrolled into the view if necessary
- GX_DISPLAYEDITWNDspecifies if the CWnd (if any) associated with the current cell’s control should receive the focus.
bCreateHint
Specifies if a hint should be created.
Return Value
Nonzero if command was successful; 0 if not.
Remarks
Call this function if you want to store and deactivate the current cell or if you want to actualize the current cell’s contents.
Calling this method is very useful if you want to ensure that the current cell’s content is transferred to the grid before performing specific operations with the grid’s data.
If bCreateHint is TRUE, the action will be performed on all views associated with the same document. This makes the function call very useful before closing and saving data to a document. The example shows how to do this.
The method creates the following hint:
CGXGridHint hint(gxHintTransferCurrentCell, m_nViewID);
hint.lParam = bSaveAndValidate;
hint.dwParam = TRUE;
hint.flags = flags;
You can override this method if you need to change the hint.
Example
This example illustrates how to ensure that the current cell’s content is saved for all views associated with a document before the document’s data are serialized.
BOOL CGridSampleDoc::CanCloseFrame(CFrameWnd* pFrame)
{
// Ensure that views can be deactivated
CView* pView = pFrame->GetActiveView( );
if (pView && pView->SendMessage(WM_GX_CANACTIVATE, 0, 0))
return FALSE;
// Ensure that the current cell is stored
if (pView->IsKindOf(RUNTIME_CLASS(CGXGridView))
&& !((CGXGridView*) pView)->TransferCurrentCell( ))
return FALSE;
// Now, I can close the view
return CDocument::CanCloseFrame(pFrame);
}
The next example illustrates how to ensure that the current cell’s content is saved for all views associated with a document before a specific dialog is displayed.
void CGridSample3View::OnViewUseractions( )
{
// Transfer Current Cell's Data to grid
if (!TransferCurrentCell( ))
return;
CUserActionsDialog dlg(GetParam( ));
if (dlg.DoModal( ) == IDOK)
{
// Redraw the grid
Redraw( );
}
}