Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Grid User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

7.4 1stGrid - Step 3

Objective Grid stores all document-specific attributes in the parameter object. When you store the parameter object in the document, all grid views connected to the document can access the same data. In OnInitialUpdate() you will see how to pass a pointer to the parameter object to the grid.

7.4.1 Modify the 1stGrid Document's Header File

This step adds a CGXParam object to the application's CDocument class. This enables all grid views to share the same parameter object.

  1. Open 1stgrdoc.h

  2. Add a public member variable to the attributes section of C1stGridDoc:

7.4.2 Modify the 1stGrid Document's Implementation File

It is good practice to add clean-up code in OnNewDocument(). This makes it easier to use the document in a single document interface (SDI) application later.

  1. Open 1stgrdoc.cpp

  2. Replace the C1stGridDoc constructor with the following version:

  3. Replace the C1stGridDoc destructor with the following version:

  4. Change the C1stGridDoc::Serialize() method as follows:

  5. Modify C1stGridDoc::OnNewDocument() as follows:

7.4.3 Modify the 1stGrid View's Implementation File

In your OnInitialUpdate() method you need to pass the pointer to the parameter object to the grid object. If the first view for a document is opened, the parameter object must be allocated and the grid data initialized. If the end user opens additional views for the same document, no initialization is necessary. The grid data is already available in the parameter object.

bFirstView = TRUE indicates that this is the first view connected to the document and therefore the data needs to be initialized.

Next, construct the parameter object and pass the pointer to the grid view.

Your existing initialization code should be bracketed with an if statement where you should check if bFirstView is TRUE.

  1. Add the following code to the beginning of C1stGridView::OnInitialUpdate():

  2. Enclose the existing initialization code with an if statement that checks for bFirstView = TRUE:

  3. Please refer to CMy1stGridView::OnInitialUpdate() in <stingray-installdir>\Samples\Grid\Tutorial\1stGrid\Step3 for a complete listing of these changes.

At this point, you can compile and run with these modifications. You can now serialize data into a document and open new views for the same data using Window|New Window. In the next section we will add support for splitting the view.

7.4.4 Add a Splitter Frame Class for 1stGrid

Next, override the OnCreateClient() method:

  1. Select View|Class View.

  2. Right click on 1stGrid and select Add, then Class.

    The Add Class dialog box appears.

  3. Select MFC in the Templates section and MFC Class in the Categories section. Then click the Add button.

    The MFC Add Class Wizard appears.

  4. In the MFC Add Class Wizard, enter CSplitterMDIChildWnd for the Name.

  5. Specify CMDIChildWnd as the Base class.

  6. Click Finish on the MFC Add Class Wizard dialog.

  7. In the Class View, right click on the newly generated class and select Properties.

  8. Click on the Overrides icon.

  9. Select the OnCreateClient event.

  10. Select <Add> OnCreateClient.

  11. The function OnCreateClient(...) is added to CSplitterMDIChildWnd.

  12. Edit the code in the file SplitterMDIChildWnd.cpp, changing OnCreateClient(…) as follows:

  13. Open SplitterMDIChildWnd.h.

  14. Add a member variable to the attributes section of CSplitterMdiChildWnd:

  15. Close and save SplitterMDIChildWnd.h and SplitterMDIChildWnd.cpp.

7.4.5 Change the 1stGrid View to the Splitter Frame Class

  1. Open 1stgrid.cpp.

  2. After #include "1stgrvw.h", add:

  3. Locate:

    and replace CMDIChildWnd with CSplitterMDIChildWnd:

7.4.6 Compile and Run 1stGrid - Step 3

At this point, you can compile and run the 1stGrid application.

  1. Compile the application and run it.

    Figure 73: 1stGrid-Step 3 in action

Congratulations on completing the 1stGrid tutorial! For more information, try these other tutorials:



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.