I'm calling this code from a button on a dockpane. The current attribute value is null and I am changing the value to a number, so there should be a change, but the modifyFeature Edit Operation is empty after the Modify. Any ideas on what might be causing this?
public static void SetFieldInt(Map? map, string layerName, string fieldName, int value)
{
try
{
if (map is null) return;
BasicFeatureLayer? featureLayer = (BasicFeatureLayer?)FindLayer(map, layerName);
if (featureLayer is null)
return;
else
{
Selection selectedFeatures = featureLayer.GetSelection();
var modifyInspector = new Inspector();
using (RowCursor rowCursor = selectedFeatures.Search())
{
while (rowCursor.MoveNext())
{
if (rowCursor.Current is not Feature feature) return;
long oid = feature.GetObjectID();
if (feature != null)
{
object den = feature[2];
}
modifyInspector.Load(featureLayer, feature.GetObjectID());
var modifyFeature = new EditOperation
{
Name = "Modify a feature"
};
modifyInspector[fieldName] = value;
modifyFeature.Modify(modifyInspector);
if (!modifyFeature.IsEmpty)
{
var result = modifyFeature.Execute();
}
}
}
}
}
catch (Exception ex)
{
throw new SystemException((System.Reflection.MethodBase.GetCurrentMethod()!.Name ?? "Unknown") + ": " + ex.Message);
}
}
Thanks!
- David Wilcox