# Data Validation through Event

## Content

InputPanel provides another way of handling input validation through event. The control comes with the [ValidateCurrentItem](/componentone/api/wpf/online-inputpanel/dotnet-framework-api/C1.WPF.InputPanel.4.6.2/C1.WPF.InputPanel.C1InputPanel.ValidateCurrentItem.html) event that can be used for validating user input.

The following image shows validation applied through event.

![](https://cdn.mescius.io/document-site-files/images/004dc683-5d50-40fc-ab9e-000a523035d7/images/event-validation.png)

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](/componentone/docs/wpf/online-inputpanel/QuickStart).

```vbnet
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
```

```csharp
private void InPanel_ValidateCurrentItem
    (object sender, System.ComponentModel.CancelEventArgs e)
{
    C1InputPanel inputPanel = sender as C1InputPanel;
    Customer customer = inputPanel.CurrentItem as Customer;
    if (customer != null)
    {
        var errorList = new ObservableCollection<ErrorInfo>();
        if (customer.Name != null && 
            string.IsNullOrWhiteSpace(customer.Name.ToString()))
        {
            errorList.Add(new ErrorInfo { ErrorInputName = "Name", 
                ErrorContent = "This field cannot be empty." });
        }
        if (customer.Weight > 110)
        {
            errorList.Add(new ErrorInfo { ErrorInputName = "Weight", 
                ErrorContent = "Value out of range." });
        }
        inputPanel.ValidationErrors = errorList;
        if (errorList.Count > 0)
        {
            e.Cancel = true;
        }
    }
}
```

## See Also

[Property Level Validation](/componentone/docs/wpf/online-inputpanel/Features/DataValidation/Property-Level-Validation)