I am in the process of upgrading my users to the newest version of ArcGIS Pro 2.4.3 and testing my code. It appears that CancelEdit is not performing as expecting in the OnRowChangeEvent? It seems to work in OnRowDeleteEvent but not in OnRowChange?
else if (ConditionTrue) //rollback
{
//CANCEL the Redraw Change
args.CancelEdit(() => ChangeError("Changes Not Allowed!", "Parent Shape Cannot be changed"));
}
I also put in simply args.CancelEdit() and that failed too
Solved! Go to Solution.
I would keep using the Inspector pattern outside of the row events as its just too convenient to use over the 'geodatabase' api within edit operations.
I can seem to figure out why this doesn't work in my code. I am unable to upgrade until I allow users to either cancel their changes or stop them from performing certain changes. I upgraded my arcgis pro sdk from 2.2.3
Hi M,
Whats the datasource for the edits you want to cancel?
And confirming that the code worked at 2.2.3?
Thanks
Sean
The datasource if a featureservice and it currently works in 2.2.3 that is in our Production environment. I am moving to 2.4.3
Thanks, looking into it.
Seems to be working for me on Pro 2.4.3 against a feature service on 10.6 windows portal. All three change events are ok, they can be cancelled.
Whats your server environment?
I am on server 10.5.1.
you got your code to undo the vertex edit in the on change event?
Sure, here's the code which cancels all.
protected override void OnClick()
{
//run on MCT
QueuedTask.Run(() =>
{
var mapLayers = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>();
foreach (var layer in mapLayers)
{
var layerTable = layer.GetTable();
RowChangedEvent.Subscribe(onRowEvent, layerTable);
RowCreatedEvent.Subscribe(onRowEvent, layerTable);
RowDeletedEvent.Subscribe(onRowEvent, layerTable);
}
});
}
private void onRowEvent(RowChangedEventArgs obj)
{
obj.CancelEdit();
}
I am out now for a couple days but I will dig into this on Monday, but do you think my conditional statement around it affects something.
your canceledit is the only statement in the event. I have 3 conditionals and a try catch. But my cancel edits are the last statements run? Long shot guess without being able to strip my code down to what you have here.
again this isn’t happening in my delete event.
I have narrowed down why this is happening, but might need some guidance. It appears that in the RowChange event this is happening because I load an inspector in the event to check a value of the selected row. If that value is true i cancel the edit. This DOES NOT work in the row change event. In the delete event, I have to check a value as well using an inspector and this DOES work. When I load an inspector in the onDelete it works like it should in 2.4.3, but in onChange if I use the inspector.load for that arg and objectid, the canceledit does not work
This does not work in the onChange event (it doesn't rollback)
//This doesn't rollback the change because of the inspr.load, i have stepped through both
//with and without this line. This worked in the old version
protected async static void OnRowChangeEvent(RowChangedEventArgs args)
{
Inspector inspr = new Inspector();
long _updateOID = args.Row.GetObjectID();
//Get the layer of the selected item
FeatureClass newFC = (FeatureClass)args.Row.GetTable();
string updateItemName = newFC.GetDefinition().GetAliasName();
FeatureLayer firstFeatureLayer = FeatureServiceManagement.GetFeatureLayer(updateItemName);
//Load the inspector
await inspr.LoadAsync(firstFeatureLayer, _updateOID);
args.CancelEdit();
}
This DOES work in the onDelete event (it doesn't delete, it rolls back)
protected async static void OnRowDeleteEvent(RowChangedEventArgs args)
{
Inspector inspr = new Inspector();
long _updateOID = args.Row.GetObjectID();
//Get the layer of the selected item
FeatureClass newFC = (FeatureClass)args.Row.GetTable();
string updateItemName = newFC.GetDefinition().GetAliasName();
FeatureLayer firstFeatureLayer = FeatureServiceManagement.GetFeatureLayer(updateItemName);
//Load the inspector
await inspr.LoadAsync(firstFeatureLayer, _updateOID);
args.CancelEdit();
}