Features / Data Validation / Data Validation through Event
In This Topic
Data Validation through Event
In This Topic

InputPanel provides another way of handling input validation through event. The control comes with the ValidateCurrentItem event that can be used for validating user input.

The following image shows validation applied through event.

To implement data validation through event, subscribe the ValidateCurrentItem event in code and add validation rules in the event handler. The following code shows how to apply validation using event. This example uses the sample created in the Quick start.

Private Sub InPanel_ValidateCurrentItem(sender As Object, e As CancelEventArgs) _
    Handles InPanel.ValidateCurrentItem
    Dim inputPanel As C1InputPanel = TryCast(sender, C1InputPanel)
    Dim customer As Customer = TryCast(inputPanel.CurrentItem, Customer)

    If customer IsNot Nothing Then
        Dim errorList = New ObservableCollection(Of ErrorInfo)()

        If customer.Name IsNot Nothing AndAlso _
            String.IsNullOrWhiteSpace(customer.Name.ToString()) Then
            errorList.Add(New ErrorInfo() With { _
                .ErrorInputName = "Name", _
                .ErrorContent = "This field cannot be empty" _
            })
        End If
        If customer.Weight > 110 Then
            errorList.Add(New ErrorInfo() With { _
                .ErrorInputName = "Weight", _
                .ErrorContent = "Value out of range." _
            })
        End If
        inputPanel.ValidationErrors = errorList
        If errorList.Count > 0 Then
            e.Cancel = True
        End If
    End If
End Sub
See Also