AnsweredAssumed Answered

EditOpertion during Form event cannot be Undone

Question asked by bulla_b on Jan 5, 2018
Latest reply on Jan 10, 2018 by bulla_b

I have an EditOperation that runs on the _Click event of a form.  I'm pretty sure I have the ChainedEditOperation setup properly, as I have set this up previously in another tool I have made that work successfully.  This is my first time trying an EditOperation of a Form event.


What is happening is that edits are happening, but not showing up on the Undo Stack.  Does anyone know if there are issues with an EditOperation run on a Form event that may cause problems??  I have posted my code below, as well as the windows Form to help provide some context:


Basically it gives the user the ability to update common fields in the selected features of multiple feature classes, and the code below is for the Save button.


private void btnSave_Click(object sender, EventArgs e)
                //Give the user a chance to get out.
                if (ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Are you sure you want to update all the selected layers?", "Update Selected Features?", System.Windows.MessageBoxButton.YesNo ) == System.Windows.MessageBoxResult.No)
                this.Cursor = Cursors.WaitCursor;

                QueuedTask.Run(() =>
                    Map map = MapView.Active.Map;
                    FeatureLayer firstLayer = map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(l => l.Name.IndexOf(lstLayers.Items[0].ToString(), StringComparison.CurrentCultureIgnoreCase) >= 0).FirstOrDefault();

                    //Create the MAIN edit operation...this will show up on the Undo Stack
                    var editOperation = new ArcGIS.Desktop.Editing.EditOperation();
                    editOperation.Name = "Update Multiple Features";
                    editOperation.EditOperationType = ArcGIS.Desktop.Editing.EditOperationType.Long;

                    //Make a 'blank' edit, so that it triggers the ChainedEditOperation to work properly, later in the code
                    var inspSetup = new ArcGIS.Desktop.Editing.Attributes.Inspector();
                    inspSetup.Load(firstLayer, 1);

                    //Go through each layer in the Layers listbox
                    foreach (string layer in lstLayers.Items)

                        var currentLayer = map.FindLayers(layer).FirstOrDefault() as BasicFeatureLayer;
                        var selection = currentLayer.GetSelection();
                        IReadOnlyList<long> selectedOIDs = selection.GetObjectIDs();                       

                        foreach (var oid in selectedOIDs)
                            //Create the chained edit for the Undo stack
                            var chainedOp = editOperation.CreateChainedOperation();
                            var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();

                            insp.Load(currentLayer, oid);   //use the current selected OBJECTID as you go through the loop of selected features

                            for (int i = 0; i < gridFields.Rows.Count; i++)
                                if (gridFields.Rows[i].Cells[1].Value != null)
                                    insp[gridFields.Rows[i].Cells[0].Value.ToString()] = gridFields.Rows[i].Cells[1].Value;

                            //Save the edits and commit the changes.
                            //This will update the ChainedEditOperation, so it only shows up once in the Undo Stack
                );  //end of QueuedTask



                this.Cursor = Cursors.Default;