Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
UltraGrid Validation with attributes
posted

Hi

VS2017 & Winforms Application

I have a class with the properties of, say FirstName, LastName and Age. Above each property in the class I can define it's position and also the header text to display:

[PropertyOrder(1)],

[DisplayName("First Name")

[Browseable(true)]

public string FirstName {get; set;}

I then create a BindingList<classname> of this class and add several instances to it, the list is then applied to the DataSource of the UltraGrid control.

So my Winform now has a grid on it with 3 columns with the headers of "First Name", "Last Name" and "Age". Because it's a binding list, as soon as the user updates the data / adds new rows, the list is updated, I can then iterate through this list and save the data... All is fine... Except Validation.

So what is the best way to validate these 3 fields.. ?

Can I put [MaxLength(50)] above the two name properties to set the max length and Min/MaxValue on the Age so it's between 0 and 150 ?

I want to validate the data before it's saves to the Database, and get errors because the string is too long or the age is way to high!.

Many thanks

Parents
No Data
Reply Children
No Data