Click to See Complete Forum and Search --> : Edit Box (Single)


Charlie Curtis
April 19th, 1999, 04:29 PM
Hi,
I have two edit boxes for the user to enter date info. (Example: 01-04-1999) I have tried the EN_MAXTEXT. Problem: EN_MAXTEXT works fine, but I want to allow my user to have the cursor placed in the next field when the last character in the date is entered. Not when an extra character is entered. Would someone be so kind as to show me how I can do this? Sample code is always welcome and steps needed to implement! Thank You Very Much!
Charlie

Allen Y
April 19th, 1999, 05:19 PM
First, you need to create EN_CHANGE message handler for the first editbox.
Second, do validation in the function everytime the user typing a character in the editbox.
Third, once the user enters a valid data info or reaches the MAXLENGTH of editbox, you set the focus to the second editbox.

For example: two editboxes m_edit1 and m_edit2 (CEdit objects).
// EN_CHANGE message handler for m_edit1
void CMyXXXXX::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_CHANGE flag ORed into the lParam mask.

// TODO: Add your control notification handler code here
CString text=_T("");
m_edit1.GetWindowText(text); // get current typed text from editbox 1

if (text.GetLength() >= MAX_DATALENGTH ||
ValidateData(text) == TRUE){
m_edit2.SetFocus();
}
}

Note: the MAX_DATELENGTH is the max characters allowed in edit1.
the ValidateData() is a function you validate the data info.

Hope this will help. Good luck.

Allen