Back to Devexpress

TableView.RowEditStarting Event

wpf-devexpress-dot-xpf-dot-grid-dot-tableview-e31ce786.md

latest9.3 KB
Original Source

TableView.RowEditStarting Event

Occurs when a user starts to edit a row.

Namespace : DevExpress.Xpf.Grid

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

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public event EventHandler<RowEditStartingEventArgs> RowEditStarting
vb
Public Event RowEditStarting As EventHandler(Of RowEditStartingEventArgs)

Event Data

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

PropertyDescription
CancelGets or sets whether to cancel the start of the edit operation.
CellEditorsGets an array of the CellEditorData objects that allow you to specify settings in the Edit Form.
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.
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.

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

Handle this event to get information about the row that the user starts to edit. If you want to maintain a clean MVVM pattern and process the start of the edit operation in a View Model, create a command and bind it to the RowEditStartingCommand property.

Set the Cancel property to true to suppress the row edit operation. The moment when RowEditStarting occurs depends on the GridControl‘s edit mode.

Edit Form

If you process data edit operations in the Edit Form, the event occurs when a user opens the form.

The RowEditStartingEventArgs class contains the CellEditors property that returns an array of CellEditorData objects. Each object allows you to specify editor’s settings. When users start to edit a row, you may want to initialize values or make certain editors read-only. To do that, specify the corresponding CellEditorData.Value property or set the CellEditorData.ReadOnly property to true.

The following code sample specifies settings for the row that contains information about employees. For example, you can initialize the ID editor (CellEditors[0] in code) and disable the Department editor (CellEditors[4]) for new rows.

csharp
private void OnRowEditStarting(object sender, RowEditStartingEventArgs e) {
    if(Equals(e.RowHandle, DataControlBase.NewItemRowHandle)) {
        e.CellEditors[0].Value = grid.VisibleRowCount + 1;
        e.CellEditors[4].ReadOnly = true;

    } else {
        e.CellEditors[0].ReadOnly = true;
        e.CellEditors[4].ReadOnly = false;
    }
}
vb
Private Sub OnRowEditStarting(ByVal sender As Object, ByVal e As RowEditStartingEventArgs)
    If Equals(e.RowHandle, DataControlBase.NewItemRowHandle) Then
        e.CellEditors(0).Value = Me.grid.VisibleRowCount + 1
        e.CellEditors(4).ReadOnly = True
    Else
        e.CellEditors(0).ReadOnly = True
        e.CellEditors(4).ReadOnly = False
    End If
End Sub

View Example: Data Grid for WPF - How to Specify Edit Form Settings

In-place Editors and Edit Entire Row

The RowEditStarting event occurs when a user opens an editor in a row for the first time. The View does not activate all editors, and you cannot use the CellEditors property to specify their settings.

The following code snippets (auto-collected from DevExpress Examples) contain references to the RowEditStarting 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-edit-form-related-cells/CS/SynchronizeEditValuesInEditForm_CodeBehind/MainWindow.xaml#L19

xml
<dxg:GridControl.View>
    <dxg:TableView EditFormShowMode="Inline" RowEditStarting="OnRowEditStarting" CellValueChanging="OnEditFormCellValueChanging"/>
</dxg:GridControl.View>

wpf-data-grid-specify-edit-form-settings/CS/DefineEditFormSettings_CodeBehind/MainWindow.xaml#L13

xml
<dxg:GridControl.View>
    <dxg:TableView x:Name="view" EditFormShowMode="InlineHideRow" NewItemRowPosition="Top" RowEditStarting="OnRowEditStarting"/>
</dxg:GridControl.View>

See Also

RowEditStartingCommand

RowEditStarted

RowEditFinished

TableView Class

TableView Members

DevExpress.Xpf.Grid Namespace