| Exception | Description |
|---|---|
| System.NotSupportedException | This table/feature does not support this operation. For example, it is from a joined table. |
| ArcGIS.Core.Data.Exceptions.GeodatabaseException | A geodatabase-related exception has occurred. |
// Attach an event handler to receive notifications when a row in the selected // table is changed. The subscription targets the first <see cref="ArcGIS.Desktop.Mapping.FeatureLayer"/> found in // the active map. Use this method to monitor and respond to edits made to table records within the current map // context. Table thisTable = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault().GetTable(); RowChangedEvent.Subscribe(rowChangedEventArgs => { // set the current row changed guid when you execute the Row.Store method // used for re-entry checking Guid _currentRowChangedGuid = new(); // RowEvent callbacks are always called on the QueuedTask so there is no need // to wrap your code within a QueuedTask.Run lambda. var row = rowChangedEventArgs.Row; // check for re-entry (only if row.Store is called) if (_currentRowChangedGuid == rowChangedEventArgs.Guid) return; var fldIdx = row.FindField("POLICE_DISTRICT"); if (fldIdx != -1) { //Validate any change to �police district� // cancel the edit if validation on the field fails if (row.HasValueChanged(fldIdx)) { // cancel edit with invalid district (5) var value = row["POLICE_DISTRICT"].ToString(); if (value == "5") { //Cancel edits with invalid �police district� values rowChangedEventArgs.CancelEdit($"Police district {row["POLICE_DISTRICT"]} is invalid"); } } // update the description field row["Description"] = "Row Changed"; // this update with cause another OnRowChanged event to occur // keep track of the row guid to avoid recursion _currentRowChangedGuid = rowChangedEventArgs.Guid; row.Store(); _currentRowChangedGuid = Guid.Empty; } }, thisTable);
{
await QueuedTask.Run(() =>
{
string message = String.Empty;
bool modificationResult = false;
using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
using (Table enterpriseTable = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.piCIPCost"))
{
EditOperation editOperation = new EditOperation();
editOperation.Callback(context =>
{
QueryFilter openCutFilter = new QueryFilter { WhereClause = "ACTION = 'Open Cut'" };
using (RowCursor rowCursor = enterpriseTable.Search(openCutFilter, false))
{
TableDefinition tableDefinition = enterpriseTable.GetDefinition();
int subtypeFieldIndex = tableDefinition.FindField(tableDefinition.GetSubtypeField());
while (rowCursor.MoveNext())
{
using (Row row = rowCursor.Current)
{
// In order to update the Map and/or the attribute table.
// Has to be called before any changes are made to the row.
context.Invalidate(row);
row["ASSETNA"] = "wMainOpenCut";
if (Convert.ToDouble(row["COST"]) > 700)
{
// Abandon asset if cost is higher than 700 (if that is what you want to do).
row["ACTION"] = "Open Cut Abandon";
row[subtypeFieldIndex] = 3; //subtype value for "Abandon"
}
//After all the changes are done, persist it.
row.Store();
// Has to be called after the store too.
context.Invalidate(row);
}
}
}
}, enterpriseTable);
try
{
modificationResult = editOperation.Execute();
if (!modificationResult) message = editOperation.ErrorMessage;
}
catch (GeodatabaseException exObj)
{
message = exObj.Message;
}
}
if (!string.IsNullOrEmpty(message))
Debug.WriteLine(message);
});
}
{
await QueuedTask.Run(() =>
{
string message = String.Empty;
bool modificationResult = false;
using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
using (FeatureClass enterpriseFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.FacilitySite"))
{
FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition();
int ownTypeIndex = facilitySiteDefinition.FindField("OWNTYPE");
int areaIndex = facilitySiteDefinition.FindField(facilitySiteDefinition.GetAreaField());
EditOperation editOperation = new EditOperation();
editOperation.Callback(context =>
{
QueryFilter queryFilter = new QueryFilter
{ WhereClause = "FCODE = 'Hazardous Materials Facility' AND OWNTYPE = ' '" };
using (RowCursor rowCursor = enterpriseFeatureClass.Search(queryFilter, false))
{
while (rowCursor.MoveNext())
{
using (Feature feature = (Feature)rowCursor.Current)
{
// In order to update the Map and/or the attribute table.
// Has to be called before any changes are made to the row
context.Invalidate(feature);
// Transfer all Hazardous Material Facilities to the City.
feature[ownTypeIndex] = "Municipal";
if (Convert.ToDouble(feature[areaIndex]) > 50000)
{
// Set the Shape of the feature to whatever you need.
List<Coordinate2D> newCoordinates = new List<Coordinate2D>
{
new Coordinate2D(1021570, 1880583),
new Coordinate2D(1028730, 1880994),
new Coordinate2D(1029718, 1875644),
new Coordinate2D(1021405, 1875397)
};
feature.SetShape(new PolygonBuilderEx(newCoordinates).ToGeometry());
}
feature.Store();
// Has to be called after the store too
context.Invalidate(feature);
}
}
}
}, enterpriseFeatureClass);
try
{
modificationResult = editOperation.Execute();
if (!modificationResult) message = editOperation.ErrorMessage;
}
catch (GeodatabaseException exObj)
{
message = exObj.Message;
}
}
if (!string.IsNullOrEmpty(message))
Debug.WriteLine(message);
});
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)