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();
Hi Daniel,
Code from SDK ConstructionTool sample works fine, but it doesn't use cursor.
Thanks! Passing the map member to Modify() did the trick.
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();
});
}
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.