Print Page | Close Window

Validation of edit field control

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=4196
Printed Date: 14 May 2024 at 8:56am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Validation of edit field control
Posted By: mgampi
Subject: Validation of edit field control
Date 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




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net