CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    85

    Need help with GUI validation problem...

    I have a dialog box with a tree control and 10 edit boxes that hold strings. (The strings represent floats & ints in the underlying data). Items on the Treecontrol(1,2... n) has 10 edit boxes. The users click on the tree control to see the next item with it's edit boxes of data. My problem is this: Say for example, EditBox1 can hold a number, 0-600 only. The user enters a digit... I first tried using OnChangeEdit1 so everytime data changed in the box I'd validate it... but I ran into a problem when a user was entering data I was checking it EVERY digit entered into the box. So I tried to check it in OnKillFocusEdit1, but I noticed that when I clicked on the treecontrol from the EditBox1, that EditBox1 for the previous item was no longer in focus but eEditBox1 for the newly clicked on item WS in foucs so that's the data I got. Like the KillFocus couldn't happen fast enough. Can anybody help me please...?

    Thank you.

  2. #2
    Join Date
    Oct 2003
    Location
    New York
    Posts
    46
    "...So I tried to check it in OnKillFocusEdit1, but I noticed that when I clicked on the treecontrol from the EditBox1, that EditBox1 for the previous item was no longer in focus but eEditBox1 for the newly clicked on item WS in foucs so that's the data I got."

    I'm with you up to this point. But could you explain this a little more clearly?

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635
    Maybe use your EN_CHANGE notification to record which edit control was the last changed, then do your validation based on that.

  4. #4
    Join Date
    Jun 2002
    Posts
    395
    What's wrong with validating the control contents after every key press?

    That lets you filter out all non-numeric characters, and never allow the user to enter a number bigger or smaller than you want, before the text box gets updated.

    It's a very nice way to do things, actually, because then it is impossible for the user to enter an invalid amount. It can save a lot of validation work down the line, if you have many functions which might have to validate the values.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635
    Originally posted by wayside
    What's wrong with validating the control contents after every key press?

    That lets you filter out all non-numeric characters, and never allow the user to enter a number bigger or smaller than you want, before the text box gets updated.

    It's a very nice way to do things, actually, because then it is impossible for the user to enter an invalid amount. It can save a lot of validation work down the line, if you have many functions which might have to validate the values.
    It has its limitations. If a certain number of characters is required, and the user has entered too many or too few but is not yet finished entering data, what do you do? It's good for only allowing certain characters, but not necessarily for general validation of data.

  6. #6
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    85
    Originally posted by phone_guy
    "...So I tried to check it in OnKillFocusEdit1, but I noticed that when I clicked on the treecontrol from the EditBox1, that EditBox1 for the previous item was no longer in focus but eEditBox1 for the newly clicked on item WS in foucs so that's the data I got."

    I'm with you up to this point. But could you explain this a little more clearly?
    OK... I'll try. When a user has items expanded in the treecontrol...say Item1 & Item2 and in the focus is in EditBox#3 on the dialog....say I just entered a "100" in EditBox#3 for Item1 in the dialog, when I click from EditBox#3 to inside the treecontrol on Item2, the OnKillFocus for EditBox#3 is called but.. it sees the data of EditBox#3 for Item2 and NOT Item1!! I thought OnKillFocus would be ideal but by the time it is called it's got the wrong data. I only have this problem when clicking from one of the many editboxes to the treecontrol... not from editbox to editbox. I hope this makes more sense.... I don't know if I'm explaining it well enough. Thanks for the help..

  7. #7
    Join Date
    Jan 2004
    Location
    Earth
    Posts
    567
    Is using ES_NUMBER an option (are you just trying to make sure each only has numbers)? Is using DDV an option?

    TDM

  8. #8
    Join Date
    Oct 2003
    Location
    New York
    Posts
    46
    I think what is happening is your TreeView is recognizing the click and retrieving the data for the selected item before it receives the focus.

    I believe what you need to do here is write a message handler for the TVN_SELCHANGING notification message in your TreeView control. This will fire when you switch between item selections, but before the selection changes. In this function, call UpdateData(true). This will call the DoDataExchange() function in your Dialog Box. You can then set Data Validation rules to make sure the data is acceptable. Look here:

    http://msdn.microsoft.com/library/de...validation.asp
    DaveDaPhoneGuy

    A foolish person doesn't know what he doesn't know and isn't afraid to act on it.
    A lazy person knows what he doesn't know but does nothing about it.
    A wise person knows what he doesn't know and seeks out those that do.

  9. #9
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    85
    Originally posted by phone_guy
    I think what is happening is your TreeView is recognizing the click and retrieving the data for the selected item before it receives the focus.

    I believe what you need to do here is write a message handler for the TVN_SELCHANGING notification message in your TreeView control. This will fire when you switch between item selections, but before the selection changes. In this function, call UpdateData(true). This will call the DoDataExchange() function in your Dialog Box. You can then set Data Validation rules to make sure the data is acceptable. Look here:

    http://msdn.microsoft.com/library/de...validation.asp
    This might be what I need! I'll check it out. Thanks!

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