Version

Validate Data as Your End Users Edit a Cell

The xamDataPresenter™ control updates its data source when a cell loses focus. If you enable support for the INotifyDataErrorInfo or IDataErrorInfo interface, your end users will not see any validation information while they are actively editing a cell’s value. Instead, they must move focus away from the cell in order to see validation information. However, you can also provide feedback as your end users type in a cell by handling xamDataPresenter’s CellChanged event and setting the cell’s value manually.

The following example code demonstrates how to validate data as your end users edit a cell.

In XAML:

<igDP:XamDataPresenter Name="xamDataPresenter1" CellChanged="xamDataPresenter1_CellChanged">
    <igDP:XamDataPresenter.FieldLayoutSettings>
        <igDP:FieldLayoutSettings SupportDataErrorInfo="RecordsAndCells" />
    </igDP:XamDataPresenter.FieldLayoutSettings>
</igDP:XamDataPresenter>

In Visual Basic:

Imports Infragistics.Windows.DataPresenter.Events
...
Private Sub xamDataPresenter1_CellChanged( _
        ByVal sender As Object, _
        ByVal e As CellChangedEventArgs)
    Dim val As Object = e.Editor.Value
    If Not (TypeOf e.Cell.Record Is FilterRecord) Then
        If DBNull.Value = val Then
            val = Nothing
        End If
        e.Cell.Value = val
    End If
End Sub
...

In C#:

using Infragistics.Windows.DataPresenter.Events;
...
private void xamDataPresenter1_CellChanged(object sender, CellChangedEventArgs e)
{
    object val = e.Editor.Value;
    if (!(e.Cell.Record is FilterRecord))
    {
        if (DBNull.Value == val)
            val = null;
        e.Cell.Value = val;
    }
}
...