C# Tutorial - TextBox Validation with Error Provider in C# | FoxLearn

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to false learn in this video I'll show you how to validate user input using the data annotation validator attributes and error provider in C Windows forms application open your Visual Studio then create a new windows forms application project next right click on your project then add a reference to the system component model data annotations Library we'll create a customer class and decorate its properties with validation attributes to practice how to use the data annotation validator attributes and error provided to perform validation in a Windows forms [Music] application the advantage of using the data annotation validators is that they enable you to perform validation simply by adding one or more attributes such as a required range regular expression or string length attribute to A Class [Music] Property the required attribute enables you to Mark a property as [Music] required the range attribute enables you to validate whether the value of a property falls between a specified range of [Music] values [Music] next rebuild your project then add a data source to your form you can design a simple UI that allows you to enter customer [Music] information [Music] for [Music] the validation context class describes the type or member on which validation is performed it also enables custom validation to be added through any service that implements the service provider interface [Music] the validation res class represents a container for the results of a validation [Music] request [Music] as you can see we can easily validate user input using the data annotation validator [Music] attributes [Music] the regular expression attribute enables you to validate whether the value of a property matches a specified regular expression pattern this is the easiest way to validate first name and last name [Music] [Music] [Music] [Music] [Music] we will create an entity validator class to help us use error provider with data annotations validation attributes to show validation errors in Windows forms you can use the error provider component The NET Framework also supports showing error in data grid view to be able to show model errors in the data grid view or showing errors using error provider the model which you are using in data binding should Implement a daa error info for example data riew which is the main model which is usually used in classic ado.net applications has implemented it a error info to bring validation attributes support to our model classes we need to implement a daa error info there is a validator class in the system component model data annotations Library which has a couple of methods which allows us to validate an object or a property of an object using validation attributes you will need to override the indexer the or get the error message for the property with a given [Music] name [Music] you also need to override the air property the aor property get an error message indicating what is wrong with this [Music] object [Music] [Music] for next we will drag a datag grade view from the visual studio toolbox into our form designer and then add the data source to the data grade view [Music] control [Music] as you can see the airor provider automatically shows up in the data grid view when an invalid data error occurs thank you for watching this video and don't forget to subscribe to my channel
Info
Channel: Fox Learn
Views: 30,179
Rating: undefined out of 5
Keywords: c#, errorprovider in c#, c# tutorial, c# validation windows forms, c# textbox validation, textbox validation in c#, textbox validation in c# windows forms, foxlearn, .net, dataannotations c#, errorprovider in c# windows forms, c# validation attribute, c# validation data annotations, c# validate dataannotations, c# validate datagridview cell, c# textbox error provider, c# textbox validation errorprovider, c# winforms textbox errorprovider, c# textbox validation error
Id: 1zjIX2EtGQc
Channel Id: undefined
Length: 19min 31sec (1171 seconds)
Published: Tue Dec 15 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.