Back to Devexpress

GridViewBase.CellValueChanged Event

wpf-devexpress-dot-xpf-dot-grid-dot-gridviewbase-1fb691c4.md

latest10.7 KB
Original Source

GridViewBase.CellValueChanged Event

Occurs when a cell value is changed.

Namespace : DevExpress.Xpf.Grid

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

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public event CellValueChangedEventHandler CellValueChanged
vb
Public Event CellValueChanged As CellValueChangedEventHandler

Event Data

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

PropertyDescription
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.
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 View raises the CellValueChanged event in the following cases:

  • A user changes a cell value and closes the in-place editor.
  • You use the GridControl.SetCellValue method to change a cell value in code.

The code sample below shows how to update summary values each time a cell value is edited:

xaml
<dxg:GridControl AutoGenerateColumns="AddNew" 
                 EnableSmartColumnsGeneration="True" 
                 ItemsSource="{Binding Sales}">
    <dxg:GridControl.TotalSummary>
        <dxg:GridSummaryItem FieldName="UnitPrice" SummaryType="Sum"/>
    </dxg:GridControl.TotalSummary>
    <dxg:GridControl.View>
        <dxg:TableView CellValueChanged="view_CellValueChanged" />
    </dxg:GridControl.View>
</dxg:GridControl>
csharp
private void view_CellValueChanged(object sender, DevExpress.Xpf.Grid.CellValueChangedEventArgs e) {
    view.CommitEditing();
}
vb
Private Sub view_CellValueChanged(ByVal sender As Object, ByVal e As DevExpress.Xpf.Grid.CellValueChangedEventArgs)
    view.CommitEditing()
End Sub

The CellValueChanged event does not occur when you change a cell value in a data source.

Note

When you use a custom CellTemplate, the GridControl raises the CellValueChanged event only if the template contains a BaseEdit class descendant declared as demonstrated in the following topic: Custom In-Place Cell Editors.

The RowEventArgs.RowHandle and CellValueEventArgs.Column properties identify a cell whose value is changed. The CellValueEventArgs.Value property returns a new cell value.

Refer to the following topic for more information: Obtain and Set Cell Values in Code.

If you want to maintain a clean MVVM pattern and process cell value changes in a View Model, create a command and bind it to the CellValueChangedCommand property.

The following code snippets (auto-collected from DevExpress Examples) contain references to the CellValueChanged 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.

wpf-data-grid-filter-column-lookupedit-based-on-value-in-another-column/CS/MainWindow.xaml#L47

xml
<dxg:GridControl.View>
    <dxg:TableView AutoWidth="True" CellValueChanged="TableViewCellValueChanged" ShownEditor="OnTableViewShownEditor"/>
</dxg:GridControl.View>

wpf-data-grid-change-background-color-for-modified-cells/CS/HighlightChangedCellBehavior.cs#L29

csharp
AssociatedObject.CustomUnboundColumnData -= OnGridCustomUnboundColumnData;
View.CellValueChanged -= OnViewCellValueChanged;
base.OnDetaching();

wpf-data-grid-filter-column-lookupedit-based-on-value-in-another-column/CS/obj/Debug/net8.0-windows/MainWindow.g.cs#L81

csharp
#line 47 "..\..\..\MainWindow.xaml"
((DevExpress.Xpf.Grid.TableView)(target)).CellValueChanged += new DevExpress.Xpf.Grid.CellValueChangedEventHandler(this.TableViewCellValueChanged);

wpf-data-grid-change-background-color-for-modified-cells/VB/HighlightChangedCellBehavior.vb#L46

vb
RemoveHandler Me.AssociatedObject.CustomUnboundColumnData, AddressOf Me.OnGridCustomUnboundColumnData
RemoveHandler Me.View.CellValueChanged, AddressOf Me.OnViewCellValueChanged
MyBase.OnDetaching()

wpf-data-grid-filter-column-lookupedit-based-on-value-in-another-column/VB/obj.NetFX/x86/Debug/MainWindow.g.vb#L81

vb
#ExternalSource("..\..\..\MainWindow.xaml",47)
AddHandler CType(target,DevExpress.Xpf.Grid.TableView).CellValueChanged, New DevExpress.Xpf.Grid.CellValueChangedEventHandler(AddressOf Me.TableViewCellValueChanged)

See Also

CellValueChanging

Immediate Posting

Input Validation

GridViewBase Class

GridViewBase Members

DevExpress.Xpf.Grid Namespace