Back to Devexpress

BaseEdit.EditValueChanging Event

windowsforms-devexpress-dot-xtraeditors-dot-baseedit-1233717e.md

latest4.1 KB
Original Source

BaseEdit.EditValueChanging Event

Fires when the editor’s value is about to change.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event ChangingEventHandler EditValueChanging
vb
<DXCategory("Events")>
Public Event EditValueChanging As ChangingEventHandler

Event Data

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

PropertyDescription
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
IsBoundUpdatingEditValueFor internal use.
IsTextChangingFor internal use.
ModifiedByUserGets whether a user changed the value.
NewValueGets or sets the value which is about to be assigned to the editor. Setting the NewValue property is not supported if the editor uses masked input (RepositoryItemTextEdit.MaskSettings).
OldValueGets the editor’s value.

Remarks

The editor’s EditValueChanging event is equivalent to the RepositoryItem.EditValueChanging event, available from the BaseEdit.Properties object.

Note

Do not display modal dialogs or move focus within the EditValueChanging event, as this can lead to the loss of the current value.

Refer to the RepositoryItem.EditValueChanging event description for additional information.

The code sample below illustrates how to accept only numeric values in a text edit.

csharp
textEdit1.EditValueChanging += TextEdit1_EditValueChanging;

private void TextEdit1_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
{
    int i = 0;
    if (!int.TryParse(e.NewValue.ToString(), out i))
        e.Cancel = true;
}
vb
'INSTANT VB NOTE: This code snippet uses implicit typing. You will need to set 'Option Infer On' in the VB file or set 'Option Infer' at the project level.

Private textEdit1.EditValueChanging += AddressOf TextEdit1_EditValueChanging

Private Sub TextEdit1_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs)
    Dim value = e.NewValue.ToString()
    Dim i As Integer = 0
    If Not Integer.TryParse(value, i) Then
        e.Cancel = True
    End If
End Sub

See Also

EditValue

Text

EditValueChanged

BaseEdit Class

BaseEdit Members

DevExpress.XtraEditors Namespace