Select to view content in your preferred language

After EditOperation.ExecuteAsync(), attribute in window and table is not refreshed

1190
4
06-08-2020 04:47 PM
DanielL
Occasional Contributor

I have a button that when clicked modifies the attributes of selected lines.  The problem is that the new attribute values don't show up as updated in the attribute table or the attribute window.  But it seems to only occur on a clean undo/redo stack; if I click it again (on the same line or a different line), if I undo and then redo, if I put UndoAsync() then RedoAsync() in the code after the execute, or if I save edits and then re-select the features, the updated values show. 

Here's the code:

EditOperation operation = new EditOperation();

operation.Name = "test edit";

FeatureLayer flayer = mapMember as FeatureLayer;

Selection selectedFeatures = flayer.GetSelection();

using (RowCursor rowCursor = selectedFeatures.Search())

{

    while (rowCursor.MoveNext())

    {

        Feature feature = rowCursor.Current as Feature;

        operation.Modify(feature, "NAME", "TEST");

    }

}

operation.ExecuteAsync();

0 Kudos
4 Replies
GKmieliauskas
Esri Regular Contributor

Hi Daniel,

Code from SDK  ConstructionTool sample works fine, but it doesn't use cursor.

                    // create a new edit operation to encapsulate the string field modifications
                    var modifyStringsOperation = new EditOperation
                    {
                        Name = String.Format("Modify string field '{0}' in layer {1}.", stringFieldName, mapMember.Key.Name)
                    };
                    ICollection<long> oidSet = new List<long>();
                    var iCnt = 0;
                    // with each ObjectID of the selected feature
                    foreach (var oid in currentSelectedFeatures[mapMember.Key])
                    {
                        // set up a new dictionary with fields to modify
                        var modifiedAttributes = new Dictionary<string, object>
                        {
                            // add the name of the string field and the new attribute value to the dictionary
                            // in this example a random string is used
                            {stringFieldName, string.Format("Update {0}", ++iCnt)}
                        };
                        // put the modify operation on the editor stack
                        modifyStringsOperation.Modify(mapMember.Key, oid, modifiedAttributes);
                        oidSet.Add(oid);
                    }
                    // execute the modify operation to apply the changes
                    await modifyStringsOperation.ExecuteAsync();
0 Kudos
DanielL
Occasional Contributor

Thanks! Passing the map member to Modify() did the trick.

0 Kudos
by Anonymous User
Not applicable

Strange. Daniel's code should be ok and i tested it here, but it feels like a thread sync issue.

Given the code has to run on the background thread, how is it being called?

As a side note, Here's an example of the modify without using a cursor:

    protected override void OnClick()
    {
      QueuedTask.Run(() =>
      {
        var operation = new EditOperation();
        operation.Name = "test edit";

        var flayer = MapView.Active.Map.GetLayersAsFlattenedList().Where(l => l.Name == "Roads").First() as FeatureLayer;
        var selected = MapView.Active.Map.GetSelection();
        var flayerSelect = selected[flayer];

        var insp = new Inspector();
        insp.Load(flayer, flayerSelect);
        insp["NAME_NO"] = "TEST";

        operation.Modify(insp);
        operation.Execute();
      });
    }
  
0 Kudos
DanielL
Occasional Contributor

Sean, I got it working if I pass the map member to Modify() rather than the feature as I was doing before, as suggested in Gintautas Kmieliauskas's answer.

The code is called in QueuedTask.Run() in the button's OnClick().  But I have almost identical code that runs in a Tool's OnSketchCompleteAsync() and that runs and the table and attribute window update without issue, so in my case it seems like it might have something to do with running it from a button click.

0 Kudos