Problem with DatePicker
-
Hi Friends I am not able to get the Selected Date from the DatePicker. It is showing me the Current DateTime always. I am new with VC++. //Initializing , m_Date( CTime::GetCurrentTime()) DDX_DateTimeCtrl(pDX, IDC_DATE, m_Date); And then i am Changing the Date in DatePicker, and on Button Click Event, i have the below instruction, where i need the Selected Date but instead it is showing me CurrentDateTime() SELECT Polhsh_ID FROM Polhsh WHERE Installation_ID = %d AND Pelaths_ID = %d AND ActionType = '%s'AND Hmeromhnia= #%s# "), Installation_ID, m_Promhtheytes.GetItemData( m_Promhtheytes.GetCurSel()), ActionType, m_Date.Format( _T("%Y/%m/%d")) ); But i am always getting the Current DateTime. I know it must be something simple, But i am completely new with VC++. I hope if anybody gets time, give me some help. Thanks
Cheers Menon
-
Hi Friends I am not able to get the Selected Date from the DatePicker. It is showing me the Current DateTime always. I am new with VC++. //Initializing , m_Date( CTime::GetCurrentTime()) DDX_DateTimeCtrl(pDX, IDC_DATE, m_Date); And then i am Changing the Date in DatePicker, and on Button Click Event, i have the below instruction, where i need the Selected Date but instead it is showing me CurrentDateTime() SELECT Polhsh_ID FROM Polhsh WHERE Installation_ID = %d AND Pelaths_ID = %d AND ActionType = '%s'AND Hmeromhnia= #%s# "), Installation_ID, m_Promhtheytes.GetItemData( m_Promhtheytes.GetCurSel()), ActionType, m_Date.Format( _T("%Y/%m/%d")) ); But i am always getting the Current DateTime. I know it must be something simple, But i am completely new with VC++. I hope if anybody gets time, give me some help. Thanks
Cheers Menon
-
See UpdateData()[^] Also if your beginning you should be using a book or tutorials. If they have not covered UpdateData then they aren't any good so find another.
-
Hi Friends I am not able to get the Selected Date from the DatePicker. It is showing me the Current DateTime always. I am new with VC++. //Initializing , m_Date( CTime::GetCurrentTime()) DDX_DateTimeCtrl(pDX, IDC_DATE, m_Date); And then i am Changing the Date in DatePicker, and on Button Click Event, i have the below instruction, where i need the Selected Date but instead it is showing me CurrentDateTime() SELECT Polhsh_ID FROM Polhsh WHERE Installation_ID = %d AND Pelaths_ID = %d AND ActionType = '%s'AND Hmeromhnia= #%s# "), Installation_ID, m_Promhtheytes.GetItemData( m_Promhtheytes.GetCurSel()), ActionType, m_Date.Format( _T("%Y/%m/%d")) ); But i am always getting the Current DateTime. I know it must be something simple, But i am completely new with VC++. I hope if anybody gets time, give me some help. Thanks
Cheers Menon
This works fine for me:
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_date); // m_date is CDateTimeCtrl object
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CDbcDlg)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER1, OnChangeDateTimePicker)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()void CMyDlg::OnChangeDateTimePicker(NMHDR* pNMHDR, LRESULT* pResult)
{
COleDateTime t;
m_date.GetTime(t);
TRACE("%s\n", t.Format("%Y/%m/%d"));\*pResult = 0;
}
Note there is no
UpdateData()
call.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
This works fine for me:
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_date); // m_date is CDateTimeCtrl object
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CDbcDlg)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER1, OnChangeDateTimePicker)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()void CMyDlg::OnChangeDateTimePicker(NMHDR* pNMHDR, LRESULT* pResult)
{
COleDateTime t;
m_date.GetTime(t);
TRACE("%s\n", t.Format("%Y/%m/%d"));\*pResult = 0;
}
Note there is no
UpdateData()
call.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Thanks David My mistake or so called foolishness was i forgot the UpdateData(True) :-D:) Still Thanks
Cheers Menon
M_Menon wrote:
i forgot the UpdateData(True)...
It's not necessary when you use control variables (e.g.,
CDateTimeCtrl
instead ofCTime
).
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne