All docs
V21.2
21.2
21.1
The page you are viewing does not exist in version 21.1. This link will take you to the root page.
20.2
The page you are viewing does not exist in version 20.2. This link will take you to the root page.
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

DialogEditFormBehavior Class

Allows you to enable edit operations in the Data Grid bound to Server Mode and Instant Feedback sources.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v21.2.Extensions.dll

Declaration

public class DialogEditFormBehavior :
    Behavior<GridControl>

Remarks

Server Mode and Instant Feedback sources do not support edit operations out-of-the-box. You need to use the DialogEditFormBehavior to allow users to invoke a dialog edit form where they can modify row values:

  1. Add the DialogEditFormBehavior to Data Grid behaviors. Set its KeyProperty to a key field that you can use to find rows during edit operations.

    <dxg:GridControl x:Name="grid" ItemsSource="{Binding InstantFeedbackSource}">
        <dxmvvm:Interaction.Behaviors>
            <dxg:DialogEditFormBehavior x:Name="EditFormBehavior" KeyProperty="Id" />
        </dxmvvm:Interaction.Behaviors>
    </dxg:GridControl>
    
  2. Before a user invokes the dialog edit form, the behavior raises the CreateEditItemViewModel event and executes the CreateEditItemViewModelCommand. Use them the specify a View Model for the edit operation. The View Model includes an item that you want to edit or add to the Data Grid, the data context that describes the edit operation, and the dialog edit form‘s title.

    <dxg:GridControl x:Name="grid" ItemsSource="{Binding InstantFeedbackSource}">
        <dxmvvm:Interaction.Behaviors>
            <dxg:DialogEditFormBehavior x:Name="EditFormBehavior" KeyProperty="Id" 
                CreateEditItemViewModelCommand="{Binding CreateEditEntityViewModelCommand}" />
        </dxmvvm:Interaction.Behaviors>
    </dxg:GridControl>
    
    [DevExpress.Mvvm.DataAnnotations.Command]
    public void CreateEditEntityViewModel(DevExpress.Mvvm.Xpf.CreateEditItemViewModelArgs args) {
        var context = new IssuesContext();
        Issue item;
        if(args.Key != null)
            item = context.Issues.Find(args.Key);
        else {
            item = new Issue() { Created = DateTime.Now };
            context.Entry(item).State = EntityState.Added;
        }
        args.ViewModel = new EditItemViewModel(item, new EditIssueInfo(context, Users));
    }
    
  3. Specify the behavior’s EditTemplate property to define editors in the dialog edit form. In the template, use the data context that you defined in the previous step.

    <dxg:GridControl x:Name="grid" ItemsSource="{Binding InstantFeedbackSource}">
        <dxmvvm:Interaction.Behaviors>
            <dxg:DialogEditFormBehavior x:Name="EditFormBehavior" KeyProperty="Id">
                <dxg:DialogEditFormBehavior.EditTemplate>
                    <DataTemplate>
                        <local:IssueDetailView />
                    </DataTemplate>
                </dxg:DialogEditFormBehavior.EditTemplate>
            </dxg:DialogEditFormBehavior>
        </dxmvvm:Interaction.Behaviors>
    </dxg:GridControl>
    
    <Grid>
        <dxlc:LayoutControl x:Name="layoutControl" 
                            Orientation="Vertical" VerticalAlignment="Top" Width="300">
            <dxlc:DataLayoutItem Binding="{Binding Item.Subject}"/>
            <dxlc:LayoutItem Label="User">
                <dxe:ComboBoxEdit EditValue="{Binding Item.UserId}" ItemsSource="{Binding Tag.Users}" 
                                  ValueMember="Id" DisplayMember="Name" IsTextEditable="False"/>
            </dxlc:LayoutItem>
            <dxlc:DataLayoutItem Binding="{Binding Item.Created}"/>
            <dxlc:DataLayoutItem Binding="{Binding Item.Votes}"/>
            <dxlc:DataLayoutItem Binding="{Binding Item.Priority}"/>
        </dxlc:LayoutControl>
    </Grid> 
    
  4. Allow users to invoke the dialog edit form with a double click of a row. To do that, bind the view’s RowDoubleClickCommand to the behavior’s RowDoubleClickCommand.

    <dxg:GridControl x:Name="grid" ItemsSource="{Binding InstantFeedbackSource}">
        <dxg:GridControl.View>
            <dxg:TableView NavigationStyle="Row"
                RowDoubleClickCommand="{Binding RowDoubleClickCommand, ElementName=EditFormBehavior}" />
      </dxg:GridControl.View>
        <!-- ... -->
    </dxg:GridControl>
    

    Alternatively, you can specify InputBindings.

    <dxg:GridControl x:Name="grid" ItemsSource="{Binding InstantFeedbackSource}">
        <!-- ... -->
        <dxg:GridControl.InputBindings>
            <KeyBinding Command="{Binding UpdateCommand, ElementName=EditFormBehavior}" Key="F2" />
            <KeyBinding Command="{Binding CreateCommand, ElementName=EditFormBehavior}" Key="N" Modifiers="Control" />
        </dxg:GridControl.InputBindings>
    </dxg:GridControl>
    

    You can also bind behavior commands to button actions.

    <dxb:ToolBarControl>
        <dxb:BarButtonItem Content="Edit (F2)" Command="{Binding UpdateCommand, ElementName=EditFormBehavior}" />
        <dxb:BarButtonItem Content="New" Command="{Binding CreateCommand, ElementName=EditFormBehavior}" />
    </dxb:ToolBarControl> 
    
  5. After a user saves changes made in the dialog edit form, the behavior raises the ValidateRow event and executes the ValidateRowCommand. Use them to validate values, check database constraints, and save changes to the database.

    <dxg:GridControl x:Name="grid" ItemsSource="{Binding InstantFeedbackSource}">
        <dxmvvm:Interaction.Behaviors>
            <dxg:DialogEditFormBehavior x:Name="EditFormBehavior" KeyProperty="Id" 
                    CreateEditItemViewModelCommand="{Binding CreateEditEntityViewModelCommand}" 
                    ValidateRowCommand="{Binding ValidateRowCommand}" />
        </dxmvvm:Interaction.Behaviors>
    </dxg:GridControl>
    
    [DevExpress.Mvvm.DataAnnotations.Command]
    public void ValidateRow(DevExpress.Mvvm.Xpf.EditFormRowValidationArgs args) {
        var context = ((EditIssueInfo)args.Tag).Context;
        context.SaveChanges();
    }
    
  6. Users can remove rows from the Data Grid. To do that, they select rows and call the DeleteCommand command.

    As a result, the behavior raises the ValidateRowDeletion event and executes the ValidateRowDeletionCommand. Use them to validate rows, check database constraints, and delete rows from the database.

    <dxg:GridControl x:Name="grid" ItemsSource="{Binding InstantFeedbackSource}">
        <dxmvvm:Interaction.Behaviors>
            <dxg:DialogEditFormBehavior x:Name="EditFormBehavior" KeyProperty="Id" 
                    CreateEditItemViewModelCommand="{Binding CreateEditEntityViewModelCommand}" 
                    ValidateRowCommand="{Binding ValidateRowCommand}"
                    ValidateRowDeletionCommand="{Binding ValidateRowDeletionCommand}" />
        </dxmvvm:Interaction.Behaviors>
    </dxg:GridControl>
    
    [DevExpress.Mvvm.DataAnnotations.Command]
    public void ValidateRowDeletion(DevExpress.Mvvm.Xpf.EditFormDeleteRowsValidationArgs args) {
        var key = (int)args.Keys.Single();
        var item = new Issue() { Id = key };
        var context = new IssuesContext();
        context.Entry(item).State = EntityState.Deleted;
        context.SaveChanges();
    } 
    

    You can also add a KeyBinding to allow users to press Delete to remove selected rows:

    <dxg:GridControl x:Name="grid" ItemsSource="{Binding InstantFeedbackSource}">
        <!-- ... -->
        <dxg:GridControl.InputBindings>
            <KeyBinding Command="{Binding DeleteCommand, ElementName=EditFormBehavior}" Key="Delete" />
        </dxg:GridControl.InputBindings>
    </dxg:GridControl>
    

Examples

Instant Feedback
Server Mode

Inheritance

Object
DispatcherObject
DependencyObject
Freezable
Animatable
DevExpress.Mvvm.UI.Interactivity.AttachableObjectBase
DevExpress.Mvvm.UI.Interactivity.Behavior
DevExpress.Mvvm.UI.Interactivity.Behavior<GridControl>
DialogEditFormBehavior
See Also