Skip to main content

RepositoryItem.Validating Event

Allows you to specify whether the edit value is valid. This event does not occur if the editor’s CausesValidation property is disabled.

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v24.2.dll

Declaration

[DXCategory("Events")]
public event CancelEventHandler Validating

Event Data

The Validating event's data class is CancelEventArgs. The following properties provide information specific to this event:

Property Description
Cancel Gets or sets a value indicating whether the event should be canceled.

Remarks

The Validating event fires when a user accepts the edited value (i.e., the editor is about start the validation). This can take place in two cases:

Handle the Validating event to test the edit value against your acceptance criteria. If the entered value is not acceptable, you can set the event’s Cancel parameter to true to keep the focus on the current cell. Thus, you will force users to correct the edit value. For example, you can check whether the entered text contains only appropriate characters or if a numeric value falls into a predefined range, etc.

If you need to provide a validation error text for an in-place editor within a data-aware control (Data Grid, Tree List, etc.), do not modify the BaseEdit.ErrorText property on the editor’s Validating event, Instead, handle the parent data-aware control’s ValidatingEditor event. Refer to the See Also section below for a list of these events.

For detailed information on how to implement validation, see the Validation help topic.

The code sample below illustrates how to validate the price value.

RepositoryItemTextEdit edit = new RepositoryItemTextEdit();
edit.Validating += Edit_Validating;
gridView1.Columns["productPrice"].ColumnEdit = edit;
gridControl1.RepositoryItems.Add(edit);

private void Edit_Validating(object sender, CancelEventArgs e)
{
    var edit = sender as TextEdit;
    decimal r = 0.0M;
    if (!decimal.TryParse(edit.EditValue.ToString(), out r))
        e.Cancel = true;
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Validating event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also