Datagridview rowvalidating example

posted by | Leave a comment

This topic describes how to check the validity of data entered by end-users into a data row.

If the row fails validation, set the event's Is Valid parameter to false.

Pointing to such an error icon displays a tooltip with an error description.

In this post we will see how we can add the Validation Rule in Typed Data Table of a Typed Data Set (using Partial Class) and then how can we use this Validation on our Form in Data Grid View or Details.

If we have set one column of our Data Table Allow DBNull = False, then in Data Grid View we encounter an exception when we try to enter a Null in this column.

This exception can be handled in Data Error event of Data Grid View control. So to make it more user friendly, we do the following things,1) Set the Allow DBNull = True for the column2) Add Validation Rule in the Data Table Example: I have created a Typed Data Set Student Data Set in which I have added 1 Table First we have created 2 private methods1) Check Student Name() - validates the Student Name column2) Check Age() - validates the Age column Then we have used 2 Data Table Events1) Column Changed - in this event handler we check which column has been changed then we call the method according to that column2) Table New Row - in this event handler we execute both methods, since whole row is chagned Here we have done with our Custom Validation.

Leave a Reply

Meet and sex chat manila chatroom