Validating datagrid values


22-Dec-2017 22:38

To create a custom validation rule, create a class that derives from the Validation Rule class and implement the Validate method.Add the custom validation rule to the property is set to Updated Value so that the validation occurs only after the bound data object is updated. Add(New Course With ) End Sub End Class Public Class Course Implements IEditable Object, INotify Property Changed Private _name As String Public Property Name As String Get Return _name End Get Set(By Val value As String) If _name = value Then Return _name = value On Property Changed("Name") End Set End Property Private _number As Integer Public Property Id As Integer Get Return _number End Get Set(By Val value As Integer) If _number = value Then Return _number = value On Property Changed("Id") End Set End Property Private _start Date As Date Time Public Property Start Date As Date Time Get Return _start Date End Get Set(By Val value As Date Time) If _start Date = value Then Return _start Date = value On Property Changed("Start Date") End Set End Property Private _end Date As Date Time Public Property End Date As Date Time Get Return _end Date End Get Set(By Val value As Date Time) If _end Date = value Then Return _end Date = value On Property Changed("End Date") End Set End Property #Region "IEditable Object" Private backup Copy As Course Private in Edit As Boolean Public Sub Begin Edit() Implements IEditable Object. Property Changed Private Sub On Property Changed(By Val property Name As String) Raise Event Property Changed(Me, _ New Property Changed Event Args(property Name)) End Sub #End Region End Class Public Class Course Validation Rule Inherits Validation Rule Public Overrides Function Validate(By Val value As Object, _ By Val culture Info As System. Culture Info) _ As Validation Result Dim course As Course = _ CType(CType(value, Binding Group). Today End Sub End Class Public Class Courses Inherits Observable Collection(Of Course) Sub New() Me. Memberwise Clone(), Course) End Sub Public Sub Cancel Edit() Implements IEditable Object.

You can validate data by handling the Cell Validating event, which is raised by the Data Grid View when the current cell changes.Hi Guys, I need Some help in validating a particular coloumn in datagrid for duplicate values before inserting into database. Please help with some example code.appreciate our help.