Back to Devexpress

ColumnView.CellValueChanged Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-4b918aae.md

latest6.2 KB
Original Source

ColumnView.CellValueChanged Event

Fires immediately after a cell value has been changed.

Namespace : DevExpress.XtraGrid.Views.Base

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Property Changed")]
public event CellValueChangedEventHandler CellValueChanged
vb
<DXCategory("Property Changed")>
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
ColumnGets the column that contains the processed cell.
OldValueGets the cell’s previous value.
RowHandleGets the handle of the row that contains the processed cell.
ValueGets the current cell value.

Remarks

The CellValueChanged event fires when:

  • a user has changed the in-place editor’s value and now closes this editor;
  • the ColumnView.SetRowCellValue method or other Grid API was used to change a cell value in code.

The event does not fire when a cell value changes on a data source level.

Example

The following sample code handles the ColumnView.CellValueChanged event to update the FullName column value after the FirstName column value has been changed.

csharp
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.BandedGrid;

private void bandedGridView1_CellValueChanged(object sender, CellValueChangedEventArgs e) {
    BandedGridView view = sender as BandedGridView;
    if (view == null) return;
    if (e.Column.Caption != "FirstName") return;
    string cellValue = e.Value.ToString() + " " + view.GetRowCellValue(e.RowHandle, view.Columns["LastName"]).ToString();
    view.SetRowCellValue(e.RowHandle, view.Columns["FullName"], cellValue);
}
vb
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Views.BandedGrid

Private Sub BandedGridView1_CellValueChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) Handles BandedGridView1.CellValueChanged
    Dim view As BandedGridView = sender
    If view Is Nothing Then
        Return
    End If
    If e.Column.Caption <> "FirstName" Then
        Return
    End If
    Dim cellValue As String = e.Value.ToString() + " " + view.GetRowCellValue(e.RowHandle, view.Columns("LastName")).ToString()
    view.SetRowCellValue(e.RowHandle, view.Columns("FullName"), cellValue)
End Sub

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.

winforms-grid-multi-cell-editing/CS/MultiSelectionEditingHelper.cs#L24

csharp
this.view.MouseUp += view_MouseUp;
this.view.CellValueChanged += view_CellValueChanged;
this.view.MouseDown += view_MouseDown;

winforms-grid-highlight-modified-cells/CS/Form1.cs#L16

csharp
gridView1.RowCellStyle += gridView1_RowCellStyle;
    gridView1.CellValueChanged += gridView1_CellValueChanged;
}

winforms-grid-multi-cell-editing/VB/MultiSelectionEditingHelper.vb#L23

vb
AddHandler Me.view.MouseUp, AddressOf view_MouseUp
AddHandler Me.view.CellValueChanged, AddressOf view_CellValueChanged
AddHandler Me.view.MouseDown, AddressOf view_MouseDown

winforms-grid-highlight-modified-cells/VB/Form1.vb#L18

vb
AddHandler gridView1.RowCellStyle, AddressOf gridView1_RowCellStyle
    AddHandler gridView1.CellValueChanged, AddressOf gridView1_CellValueChanged
End Sub

See Also

CellValueChanging

SetRowCellValue

GridControl - Is there an event raised when a data source value is changed

ColumnView Class

ColumnView Members

DevExpress.XtraGrid.Views.Base Namespace