How can I stop duplicated edits in EditCompletedEvents?

327
3
Jump to solution
01-04-2019 01:08 PM
KylePerri
Esri Contributor

I am trying to edit a field whenever an edit occurs on a feature layer, however when I make the edit the OnEditCompletedEvent fires again because of my edit. This also causes problems with undo, because anytime I undo something the OnEditCompletedEvent fires so if I undo my edit, it just gets re-edited back in. Is there any way around this?

0 Kudos
1 Solution

Accepted Solutions
SeanJones
Esri Regular Contributor

Kyle,

You can assign your EditOperation an event token then check for that on the next pass.

You can also use the CompletedType property on EditCompletedEventArgs to check for the type of operation that is firing the event (save/discard, undo/redo, an operation). EditCompletedEvent fires often.

What sorts of edits are you doing here?

Here's an example that would need more trapping.

    private Task onEditCompletedEvent(EditCompletedEventArgs arg)
    {
      if ((int?)arg.EventToken == 42)
        return Task.CompletedTask;

      var mapLayers = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>();
      var editop = new EditOperation();
      editop.Name = "Extra edit";
      editop.EventToken = 42;
      editop.Create(mapLayers.First());
      editop.Execute();

      return Task.CompletedTask;
    }

View solution in original post

3 Replies
SeanJones
Esri Regular Contributor

Kyle,

You can assign your EditOperation an event token then check for that on the next pass.

You can also use the CompletedType property on EditCompletedEventArgs to check for the type of operation that is firing the event (save/discard, undo/redo, an operation). EditCompletedEvent fires often.

What sorts of edits are you doing here?

Here's an example that would need more trapping.

    private Task onEditCompletedEvent(EditCompletedEventArgs arg)
    {
      if ((int?)arg.EventToken == 42)
        return Task.CompletedTask;

      var mapLayers = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>();
      var editop = new EditOperation();
      editop.Name = "Extra edit";
      editop.EventToken = 42;
      editop.Create(mapLayers.First());
      editop.Execute();

      return Task.CompletedTask;
    }

View solution in original post

KylePerri
Esri Contributor

Hey Sean,

Thanks for the reply. I am editing a Field on the Feature Class, but I am actually using an inspector to do the edits. This solutions seems good though. Is there a similar way to do that in the Inspector class?

0 Kudos
JohnJones
Esri Contributor

Not directly, but note that EditOperation.Modify(Inspector) does pretty much the same things as Inspector.Apply() does.