ErrorProvider control in C# Windows Form

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody this is Salah in this c-sharp Windows Form tutorial You're Gonna Learn to work with error provider control it's a very useful control to provide or to display the errors and to Mark the required fields of the form for example here you see I have two text boxes and these text boxes are required that means they cannot be left emptied if I do so and click on the submit button so here you see the error provided by the error provider so the error providers are attached to the text boxes and when the mouse cursor is placed on it you can see the text right it is required so it's a very useful control and it enhances the user experience so let's now see how do we code with error provider so here is our simple form we are going to validate these two text boxes with the help of error provider error provider is a control that you can find in the toolbox window all you need to do is just search for error provider right so we have two text boxes so we need to error providers drag them and leave them on the phone now you can see we have two error providers error provider one and error provider 2 one for each text box now back in the code inside the submit click event I have first some variables this Boolean variable is a control variable and then I have two string variables for reading the values from the checks boxes so there is no strange thing here and right after the variables I am controlling both the text boxes for null or NJ and here we need to program our error provider so the error provider number one is gonna call on text box one and that also means the data is not provided so we are going to change the status of our control variable from True to false and we are going to do the same with our second text box the second error provider is gonna attached to the second text box and lastly we are going to read the data only if the value in our control variable is true and then display a message box just to confirm the data is submitted or received simple application with simple logic this is our control variable if data is not provided we are setting it to false the data is not provided we are setting it to false but when the data is provided in both the text boxes we will never come inside the if statements and our control variable will remain true right so in this case we are gonna read the data from the text boxes let's now run this application and check it out okay so leave both the text boxes empty and click on the submit button and here you see the error provider are providing errors and if I provide data let's see like this click submit and you will see data is submitted one more thing that you can improve here as you can see the data is provided the data is submitted but the airport wireless are still there so we can clear the other providers when data is okay in our text boxes and to do so at the top we can call the Clear method on both the providers error providers so every time we are going to submit we will first clear the error providers and then we'll set the error again or do not set the errors if data is provided so let's now check it out so leave the text box is empty and here we see other providers now provide data to the first text box and here you see we don't see any error here but here we see the error because that is not provided and provide the data here and now that I submitted and error providers are gone right so friends that was a tutorial on error providers I will see you around in some other tutorials on c-sharp window forms thanks for watching
Info
Channel: #SmartCode
Views: 2,078
Rating: undefined out of 5
Keywords: winform, c# winform, errorprovider control
Id: _MxW3HikEq8
Channel Id: undefined
Length: 4min 35sec (275 seconds)
Published: Tue Jun 06 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.