Is it possible to listen when user edits data by using some GP tool e.g . Calculate Field or Delete Field? I want to handle this event similarly when user modifies data in edit session and I'm listening for row events:
protected void HookEvents()
{
QueuedTask.Run(() =>
{
//Listen for row events on a layer
foreach (var layer in EditorIDLayers)
{
var layerTable = layer.GetTable();
_rowCreateToken = RowCreatedEvent.Subscribe(OnRowCreated, layerTable);
_rowChangedToken = RowChangedEvent.Subscribe(OnRowChanged, layerTable);
_rowDeleteToken = RowDeletedEvent.Subscribe(OnRowDeleted, layerTable);
}
});
}
protected void OnRowChanged(RowChangedEventArgs args)
{
if (_lastEdit != args.Guid) //avoid recursion
{
EditInfo edit = new EditInfo(args);
edit.ModifyOperation();
_lastEdit = args.Guid;
}
}
//.../
public EditInfo(RowChangedEventArgs rowEvent)
{
_MainViewModel = EditorIDViewModel.GetVM();
EditOp = rowEvent.Operation;
ModifiedRow = rowEvent.Row;
}
public void ModifyOperation()
{
TableDefinition definition = ModifiedRow.GetTable().GetDefinition();
var attributes = new Dictionary<string, object>();
attributes.Add(settings.EditorField, _MainViewModel.UserName);
attributes.Add(settings.DataSourceField, _MainViewModel.SelectedDatasource.Key.Item1);
EditOp.Modify(ModifiedRow, attributes);
}
Solved! Go to Solution.
Hi,
If the GP tool is run within an edit session then the row events should fire. A GP tool will run in an edit session if there are existing pending edits or if you enable the 'Undo' in the gp tool pane.
This is true for the Calculate Field or Delete Rows tools. but not for Copy, copy Rows, Copy Features etc which do not have the 'Enable undo' checkbox on the tool UI.
What type of data are you using - shapefile, file geodatabase, enterprise, feature service?
Narelle
Try modifying the row using the row[fieldName] pattern.
private void OnRowChanged(RowChangedEventArgs args)
{
var row = args.Row;
var oid = row.GetObjectID();
if (args.EditType == EditType.Change)
{
row["Notes"] = "123";
}
}
Let me know if this doesn't work for you.
Narelle
Hi,
If the GP tool is run within an edit session then the row events should fire. A GP tool will run in an edit session if there are existing pending edits or if you enable the 'Undo' in the gp tool pane.
This is true for the Calculate Field or Delete Rows tools. but not for Copy, copy Rows, Copy Features etc which do not have the 'Enable undo' checkbox on the tool UI.
What type of data are you using - shapefile, file geodatabase, enterprise, feature service?
Narelle
Thanks for the response, Narelle. Yes, the row events fire when using GP tools within an edit session but strangely RowChangedEventArgs Guid is always {00000000-0000-0000-0000-000000000000} and if I try to use edit operation of RowChangedEventArgs:
EditOp.Modify(ModifiedRow, attributes);
it does not modify the record within row event. Nothing happens, except the changes of GP tool.
Don't know if my doing it wrong or it's a bug ?
What type of data are you using - shapefile, file geodatabase, enterprise, feature service?
I'm using file geodatabase and enterprise.
Try modifying the row using the row[fieldName] pattern.
private void OnRowChanged(RowChangedEventArgs args)
{
var row = args.Row;
var oid = row.GetObjectID();
if (args.EditType == EditType.Change)
{
row["Notes"] = "123";
}
}
Let me know if this doesn't work for you.
Narelle
Thanks a lot !! 🙂 ✌️
It seems that I got everything working by removing EditOp.Modify() and using your example.