<< Return to Main Index

< Return to Class Index

CGXGridCore::PasteCellsFromArchive

virtual BOOL PasteCellsFromArchive(CArchive& ar, const CGXRange& range, BOOL bIgnoreDiffRange = FALSE);

ar

A reference to the CArchive object.

range

Holds the currently selected range of cells in the grid.

bIgnoreDiffRange

Indicates whether it can be ignored that the specified range differs from the dimension stored in the CArchive object. If it is TRUE, no message box will be displayed if the dimension is differs.

Return Value

TRUE if operation could be performed successfully; otherwise FALSE.

Remarks

Pastes the cell contents from the CArchive to the grid. If the specified range differs from the dimension stored in the CArchive object, OnPasteDiffRange will be called to determine if the operation shall be canceled.

PasteCellsFromArchive is normally only called from CGXGridCore::Paste to paste data in internal format from the clipboard, but you may also call this method to load cells from a file in internal format (see example).

Control-Factory Specific ->

This method has been implemented using the abstraction mechanism as discussed in the chapter "Reducing the size of your application" in the user's guide. A call to the ImplementStyleDataExchange method from within the control factory class' InitializeGridComponents method will make the concrete implementation of this method available to your application.

If no concrete implementation is available this method returns FALSE. A warning will be displayed in the debug window.

END Control-Factory Specific

Example

This example shows you how you can paste data in internal format from a file:

void CGridSampleView::OnReadCells( )
{
   // pop-up file-open dlg to ask for location
   CFileDialog dlgFile(
      TRUE,
      _T(".grd"),
      NULL,
      OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
      _T("Grid Files (*.grd)|*.grd|All Files (*.*)|*.*||"));

   if (dlgFile.DoModal( ) == IDCANCEL)
      return;

   CFile gridFile;

   if (!gridFile.Open(dlgFile.GetFileName( ),
      CFile::modeRead))
   {
      TCHAR sz[255];
      wsprintf(sz, "File %s could not be opened!", dlgFile.GetFileName( ));
      AfxMessageBox(sz);
      return;
   }

   CArchive ar(&gridFile, CArchive::load);

   PasteCellsFromArchive(ar,
      CGXRange(0,1),
      TRUE);

   ar.Close( );
   gridFile.Close( );
}

See Also

CGXGridCore::OnPasteDiffRange CGXGridCore::CopyCellsToArchive CGXGridCore::Paste

CGXGridCore

Class Overview | Class Members