WPF DataGrid “Refresh” not allowed during AddNew or EditItem mvvm transaction

I have the following grid

    <DataGrid

        x:Name="TablesDataGrid"
        Grid.Column="0"
        Grid.Row="1"
        ItemsSource="{Binding FilteredModels.View}"
        AlternationCount="2"
        AutoGenerateColumns="False"
        CanUserSortColumns="True"
        CanUserReorderColumns="False"
  CanUserDeleteRows="False"
  CanUserAddRows="False"
  SelectionMode="Extended"
        IsReadOnly="False"
  SelectionUnit="FullRow"
        RowHeight="25"
  HorizontalAlignment="Stretch"
  ColumnWidth="Auto">
            <DataGrid.Columns >
                <DataGridCheckBoxColumn Width="*" Binding="{Binding IsChecked, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"  IsReadOnly="False">
                    <DataGridCheckBoxColumn.HeaderTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.CheckAll}"/>
                        </DataTemplate>
                    </DataGridCheckBoxColumn.HeaderTemplate>
                </DataGridCheckBoxColumn>
                <DataGridTextColumn Header="Source Table" Binding="{Binding SourceTableFullName}" Width="4*"></DataGridTextColumn>
                <DataGridTextColumn Header="EDW Schema"  Binding="{Binding SchemaName}" Width="2*"></DataGridTextColumn>
                <DataGridTextColumn Header="EDW Table" Binding="{Binding TableName}" Width="4*"></DataGridTextColumn>
                <DataGridTextColumn Header="Status" Binding="{Binding Status}" Width="*"></DataGridTextColumn>
            </DataGrid.Columns>
        </DataGrid>

and then I have a seachCommand command that searches the filenameModels CollectionViewSource files in view mode and then calls

this.FilteredModels.View.Refresh();

when the user checks several checkboxes and sends the grid to editmode and then performs a search, we get the following error:

WPF DataGrid 'Refresh' is not allowed during an AddNew or EditItem transaction

Is there a way to get the grid to exit edit mode when the checkbox is checked, or perhaps even when the search button is clicked or some other fix for this?

thanks!

+4
source share
2 answers

I know it's too late to answer ... but for those who are looking for an answer

cancelEdit commitEdit ,

//

this.datagrid_layers.CommitEdit();
this.datagrid_layers.CommitEdit();

//

this.datagrid_layers.CancelEdit();
this.datagrid_layers.CancelEdit();
+15

IEditableObject EndEdit gridEdit.

+3

All Articles