Select to view content in your preferred language

custom Action on Editor_EditCompleted event

1382
7
10-31-2011 03:47 AM
NoureddineEl-zaatari
Emerging Contributor
Hello,

im using the the Editor with custom commands to create an editing application, everything works fine but for deleting a feature i would like to do the following, update an attribute,, i was looking at the REST url and found out there Edit-Delete-Update operations available but never found a way to access them.

private void Editor_EditCompleted(object sender, Editor.EditEventArgs e)
        {
            if (e.Action == Editor.EditAction.DeleteSelected)
            {

            }
        }


i started fiddler and found out that it is calling applyedits through REST,

is there any direct way to update attributes instead of deleting them ?

thanks for any help
0 Kudos
7 Replies
JenniferNery
Esri Regular Contributor
Sure, instead of using Command Binding to Editor.DeleteSelected, you can use Button.Click event and in the event handler, iterate through the SelectedGraphics and set the attribute of interest.

If you are using EditorWidget, you can customize the control by following these steps: http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2010/05/28/Localizing-ArcGIS-Controls.aspx. In the EditorWidget.Style, you will find that there is a button that binds to DeleteSelected command, subscribe to its Click event instead.

If you are using Editor (similar to this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsExplicitSave), you will find a button that binds to DeleteSelected command, subscribe to its Click event instead.
0 Kudos
NoureddineEl-zaatari
Emerging Contributor
thanks, exactly what i was looking for
0 Kudos
NoureddineEl-zaatari
Emerging Contributor
one more thing, after i do the custom changes to the selected graphics, how do i tell the editor that i did some changes so that it enabled the save command button ??
0 Kudos
NoureddineEl-zaatari
Emerging Contributor
i think that im doing something wrong,

after doing the changes i check if FeatureLayer.Hasedits and it is always giving me false,,

here is my code on the button event handler

Editor editor = LayoutRoot.Resources["MyEditor"] as Editor;
            foreach (GraphicsLayer graphicsLayer in editor.GraphicsLayers)
            {
                if (graphicsLayer is FeatureLayer)
                {
                    foreach (Graphic g in graphicsLayer.SelectedGraphics)
                    {
                        g.Attributes["isDeleted"] = 1;
                    }
                    FeatureLayer flayer = graphicsLayer as FeatureLayer;
                    
                    flayer.SaveEdits();
                    flayer.SaveEditsFailed += new EventHandler<ESRI.ArcGIS.Client.Tasks.TaskFailedEventArgs>(flayer_SaveEditsFailed);
                }
            }


thanks for helping
0 Kudos
ChristopherHill
Deactivated User

Editor editor = LayoutRoot.Resources["MyEditor"] as Editor;
            foreach (GraphicsLayer graphicsLayer in editor.GraphicsLayers)
            {
                if (graphicsLayer is FeatureLayer)
                {
                    foreach (Graphic g in graphicsLayer.SelectedGraphics)
                    {
                        g.Attributes["isDeleted"] = 1;
                    }
                    FeatureLayer flayer = graphicsLayer as FeatureLayer;
                    
                    flayer.SaveEdits();
                    flayer.SaveEditsFailed += new EventHandler<ESRI.ArcGIS.Client.Tasks.TaskFailedEventArgs>(flayer_SaveEditsFailed);
                }
            }



By default FeatureLayer.AutoSave = true which means you don't have to call SaveEdits() to push your change back to the service. As soon as you edit the graphic the feature layer will push the changes back to the service. If you set FeatureLayer.AutoSave = false then you have to call SaveEdits() and you see FeatureLayer.HasEdits = true when you make changes. Also you can wire up EndSaveEdits to see when something is getting saved back through the service.

Editor editor = LayoutRoot.Resources["MyEditor"] as Editor;
            foreach (GraphicsLayer graphicsLayer in editor.GraphicsLayers)
            {
                if (graphicsLayer is FeatureLayer)
                {
                    foreach (Graphic g in graphicsLayer.SelectedGraphics)
                    {
                        g.Attributes["isDeleted"] = 1;
                    }
                    FeatureLayer flayer = graphicsLayer as FeatureLayer;
                    
                    flayer.EndSaveEdits += new EventHandler<ESRI.ArcGIS.Client.Tasks.EndEditEventArgs>(flayer_EndSaveEdits);
                    flayer.SaveEditsFailed += new EventHandler<ESRI.ArcGIS.Client.Tasks.TaskFailedEventArgs>(flayer_SaveEditsFailed);
                  
                    flayer.SaveEdits(); // <-- only need to call this if AutoSave is false
                   
                }
            }
0 Kudos
NoureddineEl-zaatari
Emerging Contributor
hi,

i think that updating is not working, there something wrong with my code maybe..

from the picker template i can create features, and the delete button when it was bound to Editor it was deleting also with no problems, but the custom delete button way is not updating my data on the server

FeatureLayer AutoSave is false and im calling saveEdits()

but events

- flayer_BeginSaveEdits
- flayer_SaveEditsFailed
- flayer_EndSaveEdits

are never triggered

private void Button_Click(object sender, RoutedEventArgs e)
        {
            Editor editor = LayoutRoot.Resources["MyEditor"] as Editor;
            foreach (GraphicsLayer graphicsLayer in editor.GraphicsLayers)
            {
                if (graphicsLayer is FeatureLayer)
                {
                    foreach (Graphic g in graphicsLayer.SelectedGraphics)
                    {
                        g.Attributes["isDeleted"] = 1;
                    }
                    FeatureLayer flayer = graphicsLayer as FeatureLayer;

                    flayer.EndSaveEdits += new EventHandler<ESRI.ArcGIS.Client.Tasks.EndEditEventArgs>(flayer_EndSaveEdits);
                    flayer.SaveEditsFailed += new EventHandler<ESRI.ArcGIS.Client.Tasks.TaskFailedEventArgs>(flayer_SaveEditsFailed);
                    flayer.BeginSaveEdits += new EventHandler<ESRI.ArcGIS.Client.Tasks.BeginEditEventArgs>(flayer_BeginSaveEdits);
                    
                    flayer.SaveEdits();
                    flayer.Update();

                }
            }
            
        }


any idea what is heppening ?
0 Kudos
NoureddineEl-zaatari
Emerging Contributor
nevermind i got it all working well in fact it was my mistake,, FieldName Spelling was wrong..

and regarding events, create an event handler on the FeatureLayer it self, not on the casted Graphics Layer.. hope it helps others..

thank you for your help and support
0 Kudos