0

I have an application in which I have an Edit Box. This edit box allows users to enter any character upto 20 characters.

Now I have written a function for handling the edit changed for event

ON_EN_CHANGE

void CDlgFloatingEdit::OnEditChanged() {    UpdateData(TRUE); }

Now when I enter a text value of 20 characters when i debug i find that until the UpdateData(TRUE) is called in this function the value of the CString gets saved properly and once the UpdateData(TRUE) is called the value gets set to NULL.

Another observation when I enter all characters as 4 then it works properly. But when I enter all characters as 1 then the value gets set to NULL.

I am not getting any clue on why this has to happen.

1 Answer 1

2

UpdateData will always copy the data from the controls into the dialog data members, that is its function. It will immediately apply any DDV data validations, including the 20 character limit on a field. If the validation fails it should display an error, but even if it doesn't it might clear out the CString data member.

3
  • Why would it clear out the CString data member. I am entering only 20 characters not more than that.
    – ckv
    Mar 25, 2011 at 5:11
  • 1
    @ckv, I'm not sure. You can always trace into the MFC source and find out what's happening - put a breakpoint into the DoDataExchange function. Mar 25, 2011 at 5:18
  • +1. I often think that UpdateData is a too blunt instrument, as it will always copy the data from the controls into all the dialog data members. Nowadays I seldom use UpdateData, DDV, or DoDataExchange.
    – dalle
    Mar 25, 2011 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.