CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2001
    Posts
    2

    validating text boxes

    Hi
    I'm trying to validate data in a text box using the lost_focus event. This works except for the text box that has the focus when the form is closed. The lost focus event does not seem to run then. Can anyone tell me the best method for validating text boxes.

    Thanks
    Simon Dennis


  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: validating text boxes

    You might take a look at the validate event (also the causesvalidation property).


  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: validating text boxes

    Write your validation procedure not in the lost focus event, but separately. On the lost focus event call this procedure as well as on form unload event. If on the form unload event validation did not pass through, do not unload the form.

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    Jun 2000
    Posts
    104

    Re: validating text boxes

    When you click on a control(like a command button ao a text box), the control takes focus before the click event is executed there by firing the lostfocus event of the previous control and the gotfocus event of the current control.But it is an exception with the form.Even when you are closing the form the text box keeps the focus and hence the lostfocus event is not fired.So follow Louri's advice and use a separete procedure and call it in lostfocus event of the textbox as well as in the unload event of the form.


  5. #5
    Join Date
    Apr 2001
    Posts
    2

    Re: validating text boxes

    Thanks everyone - problem solved



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