CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Location
    Bangalore,India
    Posts
    18

    Validation of Data

    Hello ,
    I am Kishore Kumar. I am working in a VC++ Project. I am having a strange problem in validating the data. My Dialog is having Four Edit boxes ( Number,Name,Place,Zipcode). I wrote the code for validation in the killfocus of corresponding control. My problem is Initially all the edit boxes are empty (Invalid). When the user enters number and pressed tab then focus is set to Name and Killfocus of number is called. If the number is invalid then I am showing a message and setting the focus back to Number. But the focus is alresdy on the Name its calling the Killfocus of Name and validating the name. Obviously name is empty(Invalid). So its going into an Infinite loop. Please help me.
    Thanks - Kishore.

    Kishore Kumar D
    Bangalore.
    India.

  2. #2
    Join Date
    May 1999
    Location
    Mass, USA.
    Posts
    103

    Re: Validation of Data

    Kishore,

    Use a flag (one will do) to indicate that you've programatically changed focus. Check that flag in your OnSetFocus() handler. Use OnSetFocus() instead of OnKillFocus().


    OnSetFocus (CWnd* pOldWnd)
    {
    if (!bFocusProgramaticallyChanged)
    if (pOldWnd)
    {
    validate contents of pOldWnd;
    if (invalid)
    {
    bFocusProgramaticallyChanged = TRUE;
    display error message;
    pOldWnd->SetFocus();
    bFocusProgramaticallyChanged = FALSE;
    }
    }
    }



    /ravi


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured