Rich Edit control accepting only numeric values
-
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.
-
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.
-
-
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_
-
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.
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_
-
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.
Rich Edit Control Styles:[^] ES_NUMBER Allows only digits to be entered into the edit control.
Florin Crisan
-
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.
It seems you set Number style for RichEdit of property window or with code?
-
ReadOnly or Number!? ;)
-
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_
_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
-
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.
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,