Textbox +Only numbers

Hello,

I want to control a textbox by pressing a button. If the input is not a number(double) I want to display an messagebox with an error. Sorry if this is a stupid question, I can't find it anywhere. Please help.

bye



Answer this question

Textbox +Only numbers

  • Sude Singh

    I downloaded the code but I don't understand how the code is implemented.


  • Eugene Zakhareyev

    I'm tring to do the same thing but just wondering: If I'm using CFormView instead of CDialog what do I need to do differently I tried the sample code in my CFormView class (which contains a CEdit control), but the OnChar function is not getting called.


  • jay1_z

    Do you mean the URL did not load for you Or do you mean, you did not understand how the code is implemented (assuming you downloaded the class available in that URL)

    Coendou wrote:

    Sorry but I don't get it

    Thanx anyway



  • Chris Shearer Cooper

    See http://www.codeproject.com/editctrl/xrnumericeditctrl.asp

    Coendou wrote:

    Hello,

    I want to control a textbox by pressing a button. If the input is not a number(double) I want to display an messagebox with an error. Sorry if this is a stupid question, I can't find it anywhere. Please help.

    bye



  • thegoonie

    Coendou wrote:

    I downloaded the code but I don't understand how the code is implemented.

    Ok, to get you started, here's what you can do. Create a new class derived from CEdit, say CMyEdit. Now you need to handle WM_CHAR in OnChar. You could do something like this :-

    void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    if(isdigit(nChar))
    CEdit::OnChar(nChar, nRepCnt, nFlags);
    }

    Now, add a DDX member to a dialog box edit control and set the control variable to be of type CMyEdit. Now you'll see that it only accepts numbers.

    This is a very basic control. But it should get you started.



  • cdellinger

    Sorry but I don't get it

    Thanx anyway


  • SneakPreview

    You need to override OnChar in a CEdit derived class, and not in your CDialog or CFormView derived classes.

    Dan Stevens wrote:

    I'm tring to do the same thing but just wondering: If I'm using CFormView instead of CDialog what do I need to do differently I tried the sample code in my CFormView class (which contains a CEdit control), but the OnChar function is not getting called.



  • Textbox +Only numbers