This is a migrated thread and some comments may be shown as answers.

Validation

3 Answers 239 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 02 Dec 2010, 09:11 PM
We're evaluating Telerk controls. We have a requirement for users to be able to enter numeric values only. We don't want to see mask placeholders, and in most cases no spin control, but when we do use a spin control, obviously we'd like the look and feel to be identical. I'm not clear if we should be using the numeric up/down control always and we can hide the spin control as desired, or should be using the masked edit contol.

For validation, we want to validate when the user attempts to change focus (mouse or keyboard), and force the focus to remain in the textbox if validation fails.

Any information you can provide on how Telerk helps us meet these requirements would be appreciated.

Jim

3 Answers, 1 is accepted

Sort by
0
Boyan
Telerik team
answered on 07 Dec 2010, 04:01 PM
Hello James,

Thank you for your interest in Telerik Controls for WPF.

I think that for your scenario it will be most suitable to use RadNumericUpDown. In this control you are allowed to enter numeric values only by default. You can easily remove the spin buttons by setting ShowButtons="False". You can validate the Value and write some custom code to return the focus to the control. The ValueChanged event is triggered when the control loses focus by default, so you will get the desired behavior. Note that if you don't remove the spin buttons they trigger the event also. I have attached a sample project illustrating how it can be done.

Let me know if you have further questions.

All the best,
Boyan
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
James
Top achievements
Rank 1
answered on 09 Dec 2010, 06:05 PM
Boyan,

Thanks very much for creating the sample project. If I enter an invalid value, it does indeed prevent me from changing the focus using either the mouse or the keyboard. However I noticed that if I first click on another application, then I can return to this application and click on another textbox in the form, thus changing the focus. Any ideas?
0
Pana
Telerik team
answered on 15 Dec 2010, 05:17 PM
Hi James,

We would not recommend you to lock the focus in the invalidated control.

Usually in such scenario you would have a view model with several properties and a command or two, a view that has controls bound to the view model and the view model would set the can execute of the commands to false if the data is incorrect. The view would display red marks around the incorrect input but would not lock the user in the wrong control. And the buttons triggering the command would usually go disabled. That's pretty much the recommended way to handle validation.

Locking the focus results in bad user experience as one can not click "Cancel", can not fill other fields and go back to correct the wrong input etc. I am sure that you would hardly find an MS Office application that behaves the way you describe and even if you do it sure stress the user a lot.

Note also that the focus feature is part of the framework. We can not do much about it. You can try to lock the focus to the selected control but anything you do in that direction would be hacky.

Regards,
Pana
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
NumericUpDown
Asked by
James
Top achievements
Rank 1
Answers by
Boyan
Telerik team
James
Top achievements
Rank 1
Pana
Telerik team
Share this question
or