WPF DataGrid CellEditEnded Event

I want to know every time a user edited the contents of my DataGrid cell. There is a CellEditEnding event, but it was triggered before any changes were made to the collection to which the DataGrid is bound.

My datagrid is attached to ObservableCollection<Item>, where Itemis the class automatically generated from the WCF mex endpoint.

What is the best way to find out every time a user makes changes to a collection.

UPDATE

I tried the CollectionChanged event, at the end it does not fire when it Itemreceives the changes.

+3
source share
3 answers

UpdateSourceTrigger=PropertyChanged datagrid. , CellEditEnding .

.

<DataGrid SelectionMode="Single"
          AutoGenerateColumns="False"
          CanUserAddRows="False"
          ItemsSource="{Binding Path=Items}" // This is your ObservableCollection
          SelectedIndex="{Binding SelectedIndexStory}">
          <e:Interaction.Triggers>
              <e:EventTrigger EventName="CellEditEnding">
                 <cmd:EventToCommand PassEventArgsToCommand="True" Command="{Binding EditStoryCommand}"/> // Mvvm light relay command
               </e:EventTrigger>
          </e:Interaction.Triggers>
          <DataGrid.Columns>
                    <DataGridTextColumn Header="Description"
                        Binding="{Binding Name, UpdateSourceTrigger=PropertyChanged}" /> // Name is property on the object i.e Items.Name
          </DataGrid.Columns>

</DataGrid>

UpdateSourceTrigger = PropertyChanged , target.

, .

+6

, DataGrid , - DataGrid RowEditEnding:

    private void dg_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
    {
        // dg is the DataGrid in the view
        object o = dg.ItemContainerGenerator.ItemFromContainer(e.Row);

        // myColl is the observable collection
        if (myColl.Contains(o)) { /* item in the collection was updated! */  }
    }
0

ObservableCollection CollectionChanged.

:

_listObsComponents.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ListCollectionChanged);

// ...


    void ListCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        /// Work on e.Action here (can be Add, Move, Replace...)
    }

when e.Action Replace, it means the object of your list has been replaced. This event, of course, is triggered after changes are made.

Good luck

-1
source

All Articles