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

    How to . limit the number digits in a textbox,which has number style selected

    Hi,

    I would like to know the standard way to limit the maximum and minimum number of digits entered in a textbox ,which has 'number' style selected.
    Thanks
    raji


  2. #2
    Join Date
    Jan 2001
    Posts
    30

    Re: How to . limit the number digits in a textbox,which has number style selected

    You could override the OnChange and do a length check each time there is a change.

    GetDlgItem(IDC_MYCONTROL)->GetWindowText(strText) ;
    if(strText.GetLength() > MAX_LENGTH)
    {
    strText = strText.Left(MAX_LENGTH) ;
    GetDlgItem(IDC_MYCONTROL)->SetWindowText(strText) ;
    }






  3. #3
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: How to . limit the number digits in a textbox,which has number style selected

    If your control is a part of dialog or CFormView derived class, the easiest way would be to use class wizard to insert variable of the numeric type you need. You will be able to enter min and max values to limit this value and DDV_MinMax... will validate value each time UpdateData is called, automatically.

    There is no such a thing like silly question, but there are many stupid answers.

    I don't do it for ratings. However, rating tells me how my solution worked and that is important.
    Good luck in your journey in a C++ land.

    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  4. #4
    Join Date
    Jul 2001
    Posts
    119

    Re: How to . limit the number digits in a textbox,which has number style selected

    Hi,
    Thanks for the response.I did as you suggested,but that does not seem to work.what do u think is the reason?

    Thanks
    Raji



  5. #5

    Re: How to . limit the number digits in a textbox,which has number style selected

    Since you have an edit box with the ES_NUMBER style, the user can only type in numbers (unless he/she pastes things into the editbox). Thus, you can set the max number of digits by sending the EM_SETLIMITTEXT with the edit box handle.

    You shouldn't set a min for this. For some situations, you should validate the entry when the user submits the number. Or you can validate the entry when you receive the EN_UPDATE, and pad zeroes either on the right or left side of the number (your preference) if the entered number has a number of digits less than the minimum required.


  6. #6
    Join Date
    Jul 2001
    Posts
    119

    Re: How to . limit the number digits in a textbox,which has number style selected

    Hi,

    I tried doing the same,but if I put a messagebox before the check it works,if I remove the messagebox,it does not work

    Thanks
    raji


  7. #7
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: How to . limit the number digits in a textbox,which has number style selected

    As I've mentioned in my post DoDataExchange is called after UpdateData(TRUE) call is made.

    Use class wizard to highlight edit control's ID, and insert handler for EN_CHANGE notification message. Call UpdateData(TRUE) from it.



    There is no such a thing like silly question, but there are many stupid answers.

    I don't do it for ratings. However, rating tells me how my solution worked and that is important.
    Good luck in your journey in a C++ land.

    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  8. #8
    Join Date
    Jul 2001
    Posts
    119

    Re: How to . limit the number digits in a textbox,which has number style selected

    Hi,

    Thanks for your response.But when I did that,a message box comes up and alerts about min & max value ,after every key entry.How do I supress it?

    Thanks
    Raji


  9. #9
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: How to . limit the number digits in a textbox,which has number style selected

    In reply to:


    I would like to know the standard way to limit the maximum and minimum number of digits entered in a textbox ,which has 'number' style selected.





    This is standard way.
    If user enters value smaller that minimum or larger than maximum this dialog will popup.

    If you do not want that, you will have to handle it "non-standard way" by comparing values or counting digits yourself. You can do that in EN_CHANGE message handler or overriding UpdateData (it is not virtual!).


    There is no such a thing like silly question, but there are many stupid answers.

    I don't do it for ratings. However, rating tells me how my solution worked and that is important.
    Good luck in your journey in a C++ land.

    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  10. #10
    Join Date
    Jan 2001
    Posts
    27

    Re: How to . limit the number digits in a textbox,which has number style selected

    I already answered for this in the following url
    http://www.codeguru.com/cgi-bin/bbs/...collapsed&sb=5


  11. #11
    Join Date
    Jun 2001
    Posts
    362

    Re: How to . limit the number digits in a textbox,which has number style selected

    Calling UpdateData(TRUE) in hanlder for EN_KILLFOCUS instead of EN_CHANGE should fix this.

    Brandon


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