Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Property Grid
  New Posts New Posts RSS Feed - CXTPPropertyGridItemDate date formatting
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPPropertyGridItemDate date formatting

 Post Reply Post Reply
Author
Message
abazosan View Drop Down
Newbie
Newbie


Joined: 24 May 2007
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote abazosan Quote  Post ReplyReply Direct Link To This Post Topic: CXTPPropertyGridItemDate date formatting
    Posted: 14 March 2008 at 6:15am
Hi there,
 
I'm trying to change the date format of a CXTPPropertyGridItemDate item in order to set the SYSTEM date format.
 
In the docs I've just seen the method 'SetDateFormat' that gets a string argument but I don't know how to build a string  with the system date format.
 
Is there any other way to set the dateformat of the control or make it to get the system format?
 
thank you in advance,
AB.
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1201
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post Posted: 14 March 2008 at 6:20am
Hi;
If you call SetDateFormat with an empty string, the format used will be the system date format:

CXRReportRecordItemDateTime* pDt=DYNAMIC_DOWNCAST(CXRReportRecordItemDateTime, AddItem(new CXRReportRecordItemDateTime(COleDateTime(dtCreated))));
pDt->SetFormatString(_T(""));
 
or you can create your own date item and use system API function to build the format strings like this:
 
IMPLEMENT_DYNAMIC(CCustomItemDateEdit, CXTPPropertyGridItemDate)
CCustomItemDateEdit::CCustomItemDateEdit(LPCTSTR strCaption, const COleDateTime& oleDate)
 : CXTPPropertyGridItemDate(strCaption, oleDate)
{
 Init();
}
CCustomItemDateEdit::CCustomItemDateEdit(UINT uiID, const COleDateTime& aDate)
 : CXTPPropertyGridItemDate(uiID, aDate)
{
 Init();
}
CCustomItemDateEdit::~CCustomItemDateEdit()
{
}
void CCustomItemDateEdit::Init()
{
 TCHAR lpIDate[2];
 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDATE, lpIDate, _countof(lpIDate));
 int iDateOrder=_ttoi(lpIDate);
 CString strFormat, strMaskFmt, strLiteralFmt; 
 if (iDateOrder==0)  // Month-Day-Year
 {
  strFormat=_T("%%m%s%%d%s%%Y");
  strMaskFmt=_T("00%s00%s0000");
  strLiteralFmt=_T("__%s__%s____");
 }
 else if (iDateOrder==1) // Day-Month-Year
 {
  strFormat=_T("%%d%s%%m%s%%Y");
  strMaskFmt=_T("00%s00%s0000");
  strLiteralFmt=_T("__%s__%s____");
 }
 else if (iDateOrder==2) // Year-Month-Day
 {
  strFormat=_T("%%Y%s%%m%s%%d");
  strMaskFmt=_T("0000%s00%s00");
  strLiteralFmt=_T("____%s__%s__");
 }
 TCHAR lpsDate[4];
 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDATE, lpsDate, _countof(lpsDate));
 m_strFormat.Format(strFormat, lpsDate, lpsDate);
 
 CString strMask, strLiteral;
 strMask.Format(strMaskFmt, lpsDate, lpsDate);
 strLiteral.Format(strLiteralFmt, lpsDate, lpsDate);
 SetMask(strMask, strLiteral);
 SetDate(GetDate());
}
CString CCustomItemDateEdit::Format(const COleDateTime& oleDate)
{
 if (oleDate.GetStatus() != COleDateTime::valid)
  return _T("");
 return oleDate.Format(VAR_DATEVALUEONLY);
}
Martin

Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0
Platform: Windows 10 v 22H2 (64bit)
Language: VC++ 2022
Back to Top
abazosan View Drop Down
Newbie
Newbie


Joined: 24 May 2007
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote abazosan Quote  Post ReplyReply Direct Link To This Post Posted: 17 March 2008 at 5:34am
Hi,
 
thank you for the reply;
 
I choose the first one because a quick date formatting is enough for me, and it seems to be taken the system format doing a
 
pDt->SetFormatString(_T(""));
 
but the initial date doesn't appear in the value field (it's just blank) and when I select a date from de pop up calendar, the control is not showing me the date I've just choosen. It only shows __/__/____ and nothing else.
 
Any ideas why I'm getting that?
 
thank you.
AB.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.171 seconds.