-
August 10th, 2001, 04:09 PM
#1
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
-
August 10th, 2001, 04:17 PM
#2
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) ;
}
-
August 10th, 2001, 04:47 PM
#3
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.
-
August 10th, 2001, 05:58 PM
#4
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
-
August 10th, 2001, 07:06 PM
#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.
-
August 10th, 2001, 07:16 PM
#6
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
-
August 11th, 2001, 09:41 AM
#7
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.
-
August 13th, 2001, 10:34 AM
#8
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
-
August 13th, 2001, 02:56 PM
#9
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.
-
August 13th, 2001, 03:21 PM
#10
Re: How to . limit the number digits in a textbox,which has number style selected
-
August 13th, 2001, 04:29 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|