Select to view content in your preferred language

About Editor_EditCompleted ...

5501
31
02-23-2011 06:47 AM
MarcoRosa
Emerging Contributor
Hi to all,
i'm using the editor tool and Editor_EditCompleted event: after selection this event it's fired 2 times , the first time e.Action value is "Select" , the second time the value is "Cancel".
It's correct this behaviour ?

Thank u very much
GP
0 Kudos
31 Replies
JenniferNery
Esri Regular Contributor
Giorgio,

When Editor.ContinuousMode=True it is expected to get edit.Action=Cancel because the current command is activated again. For example you select features from layer 1,2,3. EditCompleted event will report edit.Action=Select with selections from 1,2,3 first and then followed by edit.Action=Cancel.

So if you update the code-behind in post# 6 with the following, you will notice that after selection in all layers are made, a Cancel is reported.
private void Editor_EditCompleted(object sender, ESRI.ArcGIS.Client.Editor.EditEventArgs e)
{
 System.Diagnostics.Debug.WriteLine(e.Action);
 foreach (var edit in e.Edits)
  System.Diagnostics.Debug.WriteLine("id '{0}', layer '{1}'", edit.Graphic.Attributes["objectid"], edit.Layer.ID);
}


You access the layer similar way when DeleteSelected is executed.
FeatureLayer layer = edit.Layer as FeatureLayer;

Try the following XAML-code to add DeleteSelected:
<StackPanel DataContext="{StaticResource MyEditor}"  VerticalAlignment="Top" HorizontalAlignment="Center" Orientation="Horizontal">
 <Button Content="Select" Command="{Binding Select}" />
 <Button Content="Delete" Command="{Binding DeleteSelected}" />
</StackPanel>


Andy,

I have access to API v2.2 Beta Community as well but I do not find your code posted in there. Can you provide a link?

In your code, do you have Editor.ContinuousMode=True as well and is what I described above what you're seeing too?

I understand your project can be quite large, but we only need XAML and cs files. It would be ideal if you can give us only the code that will reproduce the issue.

Thanks!
0 Kudos
AndyWright
Frequent Contributor
Jennifer,

Here's a link that will get you to the bugs that have been submitted for the 2.2 API.  Mine is BUG-000011.

https://betacommunity.esri.com/project/feedback/track/list.html?cap=16C1D9C4623345308F10F0687AC949E6...

I do have ContinuousMode set to true, but I never see the cancel action come through the pipeline.  It is always multiple select actions for me.
0 Kudos
JenniferNery
Esri Regular Contributor
Oh okay I see it now. Thanks!
0 Kudos
JenniferNery
Esri Regular Contributor
Kindly check your DrawToolsViewModel.cs SetTool() method. This method whenever called subscribes to Editor.EditCompleted. This is the reason you get Select and Cancel action for every graphic that was added.

What you can do is use a read-only DrawEditor property with _drawEditor initially set to null. This will ensure that you set Editor properties and subscribe to EditCompleted events once. Instead of using _drawEditor to activate Select/Cancel/EditVertices, use DrawEditor instead.
private Editor DrawEditor
{
 get
 {
  if (_drawEditor == null)
  {
   _drawEditor = new Editor();
   _drawEditor.LayerIDs = new List<string> { DrawToolsGraphicsLayer.ID };
   _drawEditor.GeometryServiceUrl = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer";
   _drawEditor.ContinuousMode = true;
   _drawEditor.EditCompleted += new EventHandler<Editor.EditEventArgs>(_drawEditor_EditCompleted);
  }
  return _drawEditor;
 }
}
0 Kudos
MarcoRosa
Emerging Contributor
thks jennifer , i'll try and let y know
Giorgio
0 Kudos
AndyWright
Frequent Contributor
Jennifer,

I'm not sure if you got my e-mail reply to you yesterday or not, so I'll post it here as well.  Here's your e-mail ...

Kindly check your DrawToolsViewModel.cs SetTool() method. This method whenever called subscribes to Editor.EditCompleted. This is the reason you get Select and Cancel action for every graphic that was added.

What you can do is use a read-only DrawEditor property with _drawEditor initially set to null. This will ensure that you set Editor properties and subscribe to EditCompleted events once. Instead of using _drawEditor to activate Select/Cancel/EditVertices, use DrawEditor instead.

private Editor DrawEditor
{
get
{
if (_drawEditor == null)
{
_drawEditor = new Editor();
_drawEditor.LayerIDs = new List { DrawToolsGraphicsLayer.ID };
_drawEditor.GeometryServiceUrl = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer";
_drawEditor.ContinuousMode = true;
_drawEditor.EditCompleted += new EventHandler(_drawEditor_EditCompleted);
}
return _drawEditor;
}
}


And here's my reply:

The EditCompleted event only ever gets subscribed to once.  I have all of that stuff enclosed in an if statement.  The LayerIDs property is only null the first time through.  Once that gets set I can call SetTool thousands of times and the code within this if construct will never run. 

if (_drawEditor.LayerIDs == null)
            {
                _drawEditor.LayerIDs = new List<string> { DrawToolsGraphicsLayer.ID };
                _drawEditor.GeometryServiceUrl = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer";
                _drawEditor.ContinuousMode = true;
                _drawEditor.SelectionMode = DrawMode.Point;
                _drawEditor.EditCompleted += new EventHandler<Editor.EditEventArgs>(_drawEditor_EditCompleted);
            }


I tried your suggestion anyway and it didn�??t fix the problem.  If you create three points on the map, put a breakpoint in the _drawEditor_EditCompleted method, then use the select tool to individually select each point you�??ll see that the Select action gets fired multiple times.
0 Kudos
JenniferNery
Esri Regular Contributor
I actually don't have access to that e-mail but it was posted again as comment in the bug reports section so I was able to reply to it there.
0 Kudos
AndyWright
Frequent Contributor
Ok, thanks Jennifer.  I'll start replying to you directly through the bug reports forum.
0 Kudos
MarcoRosa
Emerging Contributor
Hi jennifer , understand the topic for the selection ... but i've the second problem to solve.

I try to explain u:

I have 2 feature layers on map. (i have set the editor by code .... add and remove tools).
when i click on map i can salect a poligon on each layer. I would like to understand on which layer im' working against not when i select a poligon but when i remove the selected objects from one of 2 layer.
Infact, the e.edits return a Layer not null when i add the selection , null when i remove the selection.

I'm trying a work around to solve this now , if u have any suggest for me .. thank u
Giorgio
0 Kudos
JenniferNery
Esri Regular Contributor
You need to iterate through the edits and look at edit.Graphic and edit.Layer.
private void MyEditor_EditCompleted(object sender, Editor.EditEventArgs e)
{
 if (e.Action == Editor.EditAction.DeleteSelected)
 {
  foreach (var edit in e.Edits)
  {
   //deleted graphic is edit.Graphic 
   //TODO: use edit.Layer
  }
 }
}
0 Kudos