Ensure Data Validity in WinForms Apps without Writing Code

Ensure Data Validity in WinForms Apps without Writing Code

The Validation Provider in Telerik UI for WPF allows you to define and associate multiple validation rules without coding.

The R2 2020 release of Telerik UI for WinForms came with a brand new validation management tool—the Telerik Validation Provider. Now you can define multiple validation rules and associate them with editors without having to write a single line of code!

One of the main challenges faced by WinForms developers while building desktop applications is ensuring the proper execution of the project. Very often that execution is directly tied to the users’ input. That is why, before managing the input data and submitting it to the server, it is important to ensure that all required editor controls on the form are filled out in the correct format.

I am very delighted to announce that as of R2 2020 Telerik UI for WinForms suite offers a powerful new tool for validation management—RadValidationProvider. This small, but very powerful, component provides data validation management for editor controls. You can easily define various validation rules and associate them with any RadEditorControl that is eligible for the specified validation logic.

Although RadValidationProvider allows you to define the rules programmatically, you are not required to write any code. Our main focus, while we were working on the internal component’s implementation, was to introduce an intuitive design-time experience which will facilitate the development process.

Now. let's take a deeper dive into the validation provider capabilities.

Imagine that we need to build a simple search form to book a summer holiday. Before executing the search query and find the appropriate results that the travel agency offers, we need to check the form for correctness.

Let’s start with the following design where we have two RadDateTimePicker controls for the start/end dates of the vacation, two RadSpinEditor controls to define our price range and one RadDropDownList to pick up the destination:

holiday reservation form

The first conditions that pop up in my mind in order to ensure that the search query will be correct are:

  • "From" date should be less than "To" date
  • "Minimum" price should be less than "Maximum" price
  • The holiday Destination shouldn’t be empty

Before proceeding further, just drag a RadValidationProvider from the toolbox and drop it onto the form:

RadValidationProvider in Form

Let’s start with defining the validation rules:

  1. Select RadValidationProvider and click the small arrow at the top right position in order to open the Smart Tag. Open the FilterDescriptor Collection Editor by clicking the Edit Validation Rules option in the Smart tag and add two RadValidationRuleWithTargetControl items:
  2. Adding Two RadValidationRuleWithTargetControl Items
  3. Open the Controls dropdown and check radDateTimePicker1:
  4. Checking radDateTimePicker1
  5. Then, specify the Operator, PropertyName, TargetControl (set it to radDateTimePicker2), TargetControlPropertyName and TooltipText:
  6. Specifying the Values
  7. Select the second RadValidationRuleWithTargetControl. This time, we will check radDateTimePicker2 from the Controls drop down and the TargetControl will be radDateTimePicker1:
  8. Specifying the Values 2
  9. Now, if you focus on the “From” RadDateTimePicker and select a date that is greater than the “To” RadDateTimePicker, you won’t be allowed to exit the control. Once you enter a valid value that meets that validation rule, you will be allowed to navigate to another control. If you focus on the “To” RadDateTimePicker and select a date that is less than the “From” RadDateTimePicker, the defined error message will pop up.
  10. ValidateDates
  11. In a similar way, we will define two more RadValidationRuleWithTargetControl items that validate that the “Minimum” price (radSpinEditor1) is less than the “Maximum” price (radSpinEditor2) and the “Maximum” price is greater than the “Minimum” price:
  12. Defining Two More RadValidationRuleWithTargetControl Items 1 Defining Two More RadValidationRuleWithTargetControl Items 2

Please ensure that the initial values in both RadSpinEditor controls meet the validation. Otherwise, you may remain blocked when you focus the "Minimum” price RadSpinEditor for the first time, e.g. if both controls have initial value = 0. No matter what value you enter in the "Minimum” price RadSpinEditor, you won’t be able to validate it and exit the control. ValidatePrice

  1. The next step is to check whether the user has selected a destination. Add a RadValidationRule and toggle radDropDownList1 from the Controls drop down. Then, define validation logic to check whether the SelectedIndex is not -1:

Defining Validation Logic for Destination 1

Defining Validation Logic for Destination 2

Defining Validation Logic for Destination 3

_The data type of the Value can be specified after entering a value first and then selecting the type from the dropdown. Thus, the correct expression will be serialized. _


Voilà! Without even writing a single line of code we ensured basic data validity of our search form.

data science

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

50 Data Science Jobs That Opened Just Last Week

Data Science and Analytics market evolves to adapt to the constantly changing economic and business environments. Our latest survey report suggests that as the overall Data Science and Analytics market evolves to adapt to the constantly changing economic and business environments, data scientists and AI practitioners should be aware of the skills and tools that the broader community is working on. A good grip in these skills will further help data science enthusiasts to get the best jobs that various industries in their data science functions are offering.

Data Science With Python Training | Python Data Science Course | Intellipaat

🔵 Intellipaat Data Science with Python course: https://intellipaat.com/python-for-data-science-training/In this Data Science With Python Training video, you...

Applications Of Data Science On 3D Imagery Data

The agenda of the talk included an introduction to 3D data, its applications and case studies, 3D data alignment and more.

Data Science Course in Dallas

Become a data analysis expert using the R programming language in this [data science](https://360digitmg.com/usa/data-science-using-python-and-r-programming-in-dallas "data science") certification training in Dallas, TX. You will master data...

32 Data Sets to Uplift your Skills in Data Science | Data Sets

Need a data set to practice with? Data Science Dojo has created an archive of 32 data sets for you to use to practice and improve your skills as a data scientist.