I have written a custom button using C# and Visual Studio 2019 that is included in an Add-In Ribbon in ArcGIS Pro 2.9.32729. The button has handlers for the OnRowCreated event and OnRowChanged event. When the event triggers, the button adds a group of values to the row that is included as a property of the RowChangedEventArgs object. The code works fine in response to the OnRowCreated event, but when I call the EditOperation.Execute() function in response to the OnRowChanged event, it fails. The error message I get back is a generic "Edit operation failed." There are no details in the error message that would help me figure out why this is happening. Any solutions or ideas for how to get a better error message that would help me solve this would be greatly appreciated.
Row events occur during the execution of an EditOperation, which may come from using a tool in the UI , some GP tools or add-ins. In the row event handers it is not necessary to create or execute an EditOperation to make any modifications as these are automatically appended to the currently running EditOperation, doing so will usually result in a failure or exception.
For more info see the conceptual help and editing snippets on row events.
Thank you for responding.
There appears to be a difference between OnRowCreated and OnRowChanged. The code between the two responses is nearly identical. Calling EditOp.Execute() in the response to an OnRowCreated event succeeds. Calling EditOp.Execute() in the response to OnRowChanged event results in a failure with the generic error message.
I owe you an apology. The OnRowCreated event response is in fact failing in the same way as the OnRowChanged event. I did some additional testing this morning to prove that. I added a call to the EditOperation Modify function before calling the Execute function.
Do you have a recommendation for how to add values to a row in the response to either an OnRowCreated or an OnRowChanged event?
Thank you for your time, and again my apologies for passing along incorrect information.
I have found a method for adding attributes to features in response to a RowCreatedEvent or RowChangedEvent. Instead of using the EditOperation Modify function, use the index property on the Row object that is a property of the RowChangedEventArgs object that is an event argument. Once all the values have been set, call the .Store() function on the row to save your values. The indexer works with either the field index or the field name for the value you are setting. Make sure that the code that sets the values is wrapped inside a QueuedTask.Run block. A C# code snippet:
private void OnRowCreatedHandler(RowChangedEventArgs args)
Row row = args.Row;
row = "Changed";
row["YearMade"] = 2022;
Hope this is helpful.