Click here to Skip to main content
14,022,795 members
Click here to Skip to main content
Add your own
alternative version

Stats

109.3K views
44 bookmarked
Posted 30 May 2001
Licenced CPOL

Date Time Picker control for the MFC Grid Control

, 30 May 2001
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Eugen Podsypalnikov
Software Developer COPA-DATA GmbH
Austria Austria
No Biography provided

You may also be interested in...

Pro

Comments and Discussions

 
GeneralMy vote of 3 Pin
Member 103177495-Oct-13 14:13
memberMember 103177495-Oct-13 14:13 
GeneralTab issue while editing Pin
Christian Cheney14-May-09 10:31
memberChristian Cheney14-May-09 10:31 
I ran into a problem when tabbing while editing cells. The tab key would allow entry into the date-time cell on key down, but would exit upon key up. The solution was to remove VK_TAB from the list of keys that return focus to the grid in CInPlaceDateTime::OnKeyUp() and add it to OnKeyDown. HTH


void CInPlaceDateTime::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if( (nChar == VK_TAB) || 
        (( (nChar == VK_PRIOR) || (nChar == VK_NEXT) ||
		   (nChar == VK_DOWN)  || (nChar == VK_UP)   ||
		   (nChar == VK_RIGHT) || (nChar == VK_LEFT) ) &&
		 ( m_bExitOnArrows || (GetKeyState( VK_CONTROL ) < 0) )) )
	{
		m_nLastChar = nChar;
		GetParent()->SetFocus();
		return;
	}

	CDateTimeCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}

//Tab only processed on key down so we don't get double-tabbed
void CInPlaceDateTime::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if (/*nChar == VK_TAB ||*/ nChar == VK_RETURN || nChar == VK_ESCAPE)
	{
		m_nLastChar = nChar;
		GetParent()->SetFocus();    // This will destroy this window
		return;
	}

	CDateTimeCtrl::OnKeyUp(nChar, nRepCnt, nFlags);
}

QuestionCan DATE TIME picker have NULL value Pin
anitaj18-Jun-08 20:07
memberanitaj18-Jun-08 20:07 
GeneralMinor Things Pin
Andrew Phillips7-Mar-04 19:23
memberAndrew Phillips7-Mar-04 19:23 
QuestionCalender ? Pin
Elco27-Jan-04 20:48
memberElco27-Jan-04 20:48 
GeneralBig Time Setting Bug Pin
janeyre14-Jan-03 21:50
memberjaneyre14-Jan-03 21:50 
GeneralSmall Enhancement to GridCellDateTime Pin
Jason Slocomb21-Dec-01 10:49
memberJason Slocomb21-Dec-01 10:49 
GeneralRe: Small Enhancement to GridCellDateTime Pin
sep21-Jul-03 8:54
membersep21-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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190417.4 | Last Updated 31 May 2001
Article Copyright 2001 by Eugen Podsypalnikov
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid