Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Validation of edit field control
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Validation of edit field control

 Post Reply Post Reply
Author
Message
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1198
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post Topic: Validation of edit field control
    Posted: 11 May 2006 at 11:04am

Hello;

I'm using a CXTPControlEdit derived class with a masked edit control to input timestamps.
The user should be able to insert the timestamp and before loosing focus (tabbing to next field) the input should be validated and when validation fails not loose the focus.

I tried to resolve this by writing my own CTimeScaleEdit::OnKillFocus() method.
This methode looks like

void CTimeScaleEdit::OnKillFocus()
{
   CString strText=GetEditText();
   COleDateTime dt;
   // Try to parse the string

   if (!dt.ParseDateTime(strText))
   {
      MessageBeep(0xFFFFFFFF);
      // If this fails 
     
GetEditCtrl()->SetFocus();
      return
;
   }
   else
   {
      // Reformat the string to be shown as expected
      CString strBuffer;
      GetTimestampFormatted(dt, strBuffer.GetBuffer(128), 128);
      strBuffer.ReleaseBuffer();
      SetEditText(strBuffer);
   }
   CXTPControlEdit::OnKillFocus();
}

When trying this solution the behavior is soewhat undefined because when the vaidation fails once, return keys won't be handled anymore.

What am I doing wrong? Whats the best way to handle edit control validation in command bars?

Thanx in advance

Martin

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.156 seconds.