Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Rich Edit control accepting only numeric values

Rich Edit control accepting only numeric values

Scheduled Pinned Locked Moved C / C++ / MFC
10 Posts 8 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vjasai
    wrote on last edited by
    #1

    Hi, In my application, I have to use a rich edit control which will only accept numeric values. It should not allow the user to enter the text i.e the when the user presses any alphabets..rich edit should not display. Any pointers would be greatly appreciated.

    J _ F H J 5 Replies Last reply
    0
    • V vjasai

      Hi, In my application, I have to use a rich edit control which will only accept numeric values. It should not allow the user to enter the text i.e the when the user presses any alphabets..rich edit should not display. Any pointers would be greatly appreciated.

      J Offline
      J Offline
      johnalek
      wrote on last edited by
      #2

      Hi Go to richedircontrol properties..change readonly property false...

      #sanroop#

      N _ H 3 Replies Last reply
      0
      • J johnalek

        Hi Go to richedircontrol properties..change readonly property false...

        #sanroop#

        N Offline
        N Offline
        Nishad S
        wrote on last edited by
        #3

        johnalek wrote:

        change readonly property

        :confused:

        - NS - [ODBaseBtn]

        1 Reply Last reply
        0
        • J johnalek

          Hi Go to richedircontrol properties..change readonly property false...

          #sanroop#

          _ Offline
          _ Offline
          _AnsHUMAN_
          wrote on last edited by
          #4

          Then it would not be possible for the user to enter anything in the rich edit control through the keyboard if it's a control with Read Only Property set to true.

          Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

          D 1 Reply Last reply
          0
          • V vjasai

            Hi, In my application, I have to use a rich edit control which will only accept numeric values. It should not allow the user to enter the text i.e the when the user presses any alphabets..rich edit should not display. Any pointers would be greatly appreciated.

            _ Offline
            _ Offline
            _AnsHUMAN_
            wrote on last edited by
            #5

            Probably you need something like this:

            void CMyDlgDlg::OnEnChangeRichedit21()
            {
            	CString str;
            	m_richedit.GetWindowText (str);
            	bool flag = false;
            	for ( int i = 0 ; i < str.GetLength () ; i++)
            	{
            		if(str.GetAt (i) >= '0' && str.GetAt (i) <= '9')
            		{
            			flag = true;
            		}
            		else
            		{
            			m_richedit.SetWindowText (lastCorrectText);
            			flag = false;
            			break;
            		}
            	}
            	if(flag)
            		lastCorrectText = str.Left(i+1);
            	m_richedit.SetSel(-1,-1); // Keep the cursor at the end of the string being displayed
            }
            

            Optimize the code for ur use now. I haven't tested it but hope that it works :-\

            Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

            1 Reply Last reply
            0
            • V vjasai

              Hi, In my application, I have to use a rich edit control which will only accept numeric values. It should not allow the user to enter the text i.e the when the user presses any alphabets..rich edit should not display. Any pointers would be greatly appreciated.

              F Offline
              F Offline
              Florin Crisan
              wrote on last edited by
              #6

              Rich Edit Control Styles:[^] ES_NUMBER Allows only digits to be entered into the edit control.

              Florin Crisan

              1 Reply Last reply
              0
              • J johnalek

                Hi Go to richedircontrol properties..change readonly property false...

                #sanroop#

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #7

                ReadOnly or Number!? ;)

                1 Reply Last reply
                0
                • V vjasai

                  Hi, In my application, I have to use a rich edit control which will only accept numeric values. It should not allow the user to enter the text i.e the when the user presses any alphabets..rich edit should not display. Any pointers would be greatly appreciated.

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #8

                  It seems you set Number style for RichEdit of property window or with code?

                  1 Reply Last reply
                  0
                  • _ _AnsHUMAN_

                    Then it would not be possible for the user to enter anything in the rich edit control through the keyboard if it's a control with Read Only Property set to true.

                    Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    _AnShUmAn_ wrote:

                    Then it would not be possible for the user to enter anything in the rich edit control through the keyboard if it's a control with Read Only Property set to true.

                    While johnalek's suggestion had nothing to do with the OP's question, an edit control whose Read-Only property is set to False means it can be interacted with via the keyboard.

                    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    1 Reply Last reply
                    0
                    • V vjasai

                      Hi, In my application, I have to use a rich edit control which will only accept numeric values. It should not allow the user to enter the text i.e the when the user presses any alphabets..rich edit should not display. Any pointers would be greatly appreciated.

                      J Offline
                      J Offline
                      Joan M
                      wrote on last edited by
                      #10

                      Setting the ESNUMBER style is a great solution, but (at least it happens in the CEdit) then you won't be able to use floating point values like 12.3 or 12,3. If you need to use floating point values the only thing I can think of is to extend the RicheditControl implementing a new class and implement a filter like _AnShUmAn_ has told you. Hope this helps. Best regards,

                      https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups