Objective Grid : PART I User’s Guide : Chapter 9 DlgGrid Tutorial : Modify CDlgGridDlg::OnInitDialog()
Modify CDlgGridDlg::OnInitDialog()
This step modifies OnInitDialog to subclass the user control on the dialog template and to perform some basic grid initialization.
1. Open DlgGridDlg.cpp.
2. Add the following line after #include "stdafx.h":
 
#include "MyGridWnd.h"
3. Search for OnInitDialog.
4. Replace the // TODO: line with the following code:
 
// Please refer to the MFC documentation on
// SubclassDlgItem for information on this
// call. This makes sure that our C++ grid
// window class subclasses the window that
// is created with the User Control.
m_wndGrid.SubclassDlgItem(IDC_GRID, this);
 
// Initialize the grid. For CWnd based grids
// this call is essential. For view based
// grids this initialization is done in
// OnInitialUpdate.
m_wndGrid.Initialize();
 
// Sample setup for the grid
m_wndGrid.GetParam()->EnableUndo(FALSE);
 
m_wndGrid.SetRowCount(100);
m_wndGrid.SetColCount(20);
 
m_wndGrid.SetStyleRange(CGXRange(1,1),
CGXStyle()
.SetValue("Hello")
);
m_wndGrid.SetStyleRange(CGXRange(1,2),
CGXStyle()
.SetValue("World!")
);
 
m_wndGrid.GetParam()->EnableUndo(TRUE);
5. Save and close DlgGridDlg.cpp.