65.9K
CodeProject is changing. Read more.
Home

Date Time Picker control for the MFC Grid Control

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.67/5 (6 votes)

May 31, 2001

CPOL
viewsIcon

116674

downloadIcon

2464

A DateTime control for editing date or time values inplace in the MFC Grid Control

Sample Image - GridCellDateTime.gif

Introduction

This is a simple drop-in cell class for Chris Maunder's MFC Grid Control. The cell's class is CGridCellDateTime and is used in exactly the same way as other grid cell types.

The edit window that is created when the cell goes into edit mode is of type CDateTimeCtrl (so you need at least IE3 installed on your system for it to run)

Possible usage

MyDialog::OnInitDialog()
{
    ...  
    m_Grid.SetRowCount(44);
    m_Grid.SetColumnCount(22);
    m_Grid.SetFixedRowCount();

    for (int i =1; i <44; i++) 
    {
       m_Grid.SetCellType(i, 0, RUNTIME_CLASS(CGridCellDateTime));
       ((CGridCellDateTime*) m_Grid.GetCell(i, 0))->Init(DTS_SHORTDATEFORMAT);

       m_Grid.SetCellType(i, 1, RUNTIME_CLASS(CGridCellDateTime));
       ((CGridCellDateTime*) m_Grid.GetCell(i, 1))->Init(DTS_TIMEFORMAT);
    }
    ...
}