How can I use a grid in a dialog?
The following steps are necessary to embed a grid in a dialog.
Create or open your dialog template. Choose the user control icon, drag it into the the dialog and open its property page. Enter "GXWND" as class name into the class box and specify the style bits for the grid:
-
0x50b10000 to display both scrollbars and a border
- 0x50810000 to display no scrollbars but a border
See the definitions for windows style bits in your windows.h header file.
If you created a new dialog, you should now create your dialog class with ClassWizard.
Embed an object of you derived grid class in the dialog.
class CDerGridDialog : public CDialog
{
// Construction
public:
CDerGridDialog(CWnd* pParent = NULL); // standard constructor
// Dialog Data
CMyGridWnd m_wndGrid;
...
Add the OnInitDialog member to you dialog class (WM_INITDIALOG-message). In OnInitDialog, you can initialize the grid:
BOOL CDerGridDialog::OnInitDialog( )
{
CDialog::OnInitDialog( );
m_wndGrid.SubclassDlgItem(IDC_GRIDSAMPLE, this);
m_wndGrid.Initialize( );
…
Note: If you want to use the grid in a formview, you should override OnInitialUpdate instead of OnInitDialog.
In the dialogs DoDataExchange method add
DDV_GXGridWnd(pDX, &m_wndGrid);