Click here to Skip to main content
15,897,518 members
Articles / Desktop Programming / MFC
Article

Date Time Picker control for the MFC Grid Control

Rate me:
Please Sign up or sign in to vote.
4.67/5 (6 votes)
30 May 2001CPOL 115.9K   2.5K   44   8
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);
    }
    ...
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer COPA-DATA GmbH
Austria Austria
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 3 Pin
Member 103177495-Oct-13 14:13
Member 103177495-Oct-13 14:13 
GeneralTab issue while editing Pin
Christian Cheney14-May-09 10:31
Christian Cheney14-May-09 10:31 
QuestionCan DATE TIME picker have NULL value Pin
anitaj18-Jun-08 20:07
anitaj18-Jun-08 20:07 
GeneralMinor Things Pin
Andrew Phillips7-Mar-04 19:23
Andrew Phillips7-Mar-04 19:23 
QuestionCalender ? Pin
Elco27-Jan-04 20:48
Elco27-Jan-04 20:48 
GeneralBig Time Setting Bug Pin
janeyre14-Jan-03 21:50
janeyre14-Jan-03 21:50 
GeneralSmall Enhancement to GridCellDateTime Pin
Jason Slocomb21-Dec-01 10:49
Jason Slocomb21-Dec-01 10:49 
Hello all --

First off thanks to Chris (et al) who made this awesome Grid. It's a fine piece of work. Ditto to the people making new GridCell Types!

Anyhoo, I was noticing that GridCellDateTime doesn't work too well when used with the DTS_SHORTDATEFORMAT. This is the style of CDateTimeCtrl that displays a Month Calendar Control when the user clicks the drop down.

The reason seems to be that the OnKillFocus() handler is called immediately when you leave focus and make a selection on said Calendar Control.

Since OnKillFocus() calls the EndEdit() function, it blows away the InPlaceEdit object. This never allows the users selection to be displayed in the edit field or stored in the CTime member.

The solution I came up with is to comment out the EndEdit() call in OnKillFocus and add a ON_NOTIFY_REFLECT() handler for the DTN_CLOSEUP message. This is the message for indicating that the calendar control is about to disappear. Inside my handler, I call EndEdit().

An even better solution would be to inspect the style of the GridCellDateTime while in OnKillFocus. Then you could choose whether or not to call EndEdit(), since the message DTN_CLOSEUP is only sent for the styles that display the Month Calendar Control.

-Jason
GeneralRe: Small Enhancement to GridCellDateTime Pin
sep21-Jul-03 8:54
sep21-Jul-03 8:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.