Back to Devexpress

GridViewBase.CellEditorValueChanging Event

wpf-devexpress-dot-xpf-dot-grid-dot-gridviewbase-22087399.md

latest6.7 KB
Original Source

GridViewBase.CellEditorValueChanging Event

Occurs when the cell editor value is changed and allows you to cancel changes.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public event CellEditorValueChangingEventHandler CellEditorValueChanging
vb
Public Event CellEditorValueChanging As CellEditorValueChangingEventHandler

Event Data

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

PropertyDescription
CancelGets or sets whether the CellEditorValueChanging event is canceled.
CellGets a processed cell. Inherited from CellValueEventArgs.
ColumnGets a column that contains the edited cell. Inherited from CellValueEventArgs.
HandledGets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.
OldValueGets the cell’s previous value. Inherited from CellValueChangedEventArgs.
OriginalSourceGets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEventGets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
RowGets the processed row. Inherited from RowEventArgs.
RowHandleGets the processed row’s handle. Inherited from RowEventArgs.
SourceGets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.
ValueGets or sets the processed cell’s value. Inherited from CellValueEventArgs.

The event data class exposes the following methods:

MethodDescription
InvokeEventHandler(Delegate, Object)When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.
OnSetSource(Object)When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.

Remarks

The CellEditorValueChanging event is raised only when a user modifies a cell value using an in-place editor (a user types or deletes a character, chooses a value from a drop-down list, etc.). You cannot raise the event in code.

To restore the previous cell editor value (and prevent the CellValueChanging event from occurring), set the Cancel property to true.

Example

The following example prompts a user before changing a cell value (if the action is canceled, the cell value remains unchanged):

xaml
<ThemedWindow ...
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid">
    <Grid>
        <dxg:GridControl ...>
            <dxg:GridControl.View>
                <dxg:TableView ...
                    CellEditorValueChanging="OnIsActiveCellEditorChanging"/>
            </dxg:GridControl.View>
        </dxg:GridControl>
    </Grid>
</ThemedWindow>
csharp
void OnIsActiveCellEditorChanging(object sender, CellEditorValueChangingEventArgs e) {
    if (e.Column.FieldName == "IsActive") {
        var result = MessageBox.Show(
            "Would you like to change the Active status?",
            "Warning",
            MessageBoxButton.OKCancel,
            MessageBoxImage.Question,
            MessageBoxResult.OK
        );
        e.Cancel = (result == MessageBoxResult.Cancel);
    }
}

See Also

GridViewBase Class

GridViewBase Members

DevExpress.Xpf.Grid Namespace