Friday, 25 May 2018

arcobjects - Determine which field is being modified during OnChangeFeature event


In the OnChangeFeature event is there a way to determine which field was just edited causing the event to fire? I'm doing several tasks in OnChangeFeature that only need to happen when certain fields are edited, so being able to determine which field just changed would be helpful. Any suggestions?



Answer



Not sure why everyone is commenting instead of answering but here's an example with both an IRowChanges and an IFeatureChanges (in case you are interested in the geometry). I did have to strip out some lines of code, but this should be close:


IRowChanges: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//0025000007vw000000


        IRowChanges rowChanges = obj as IRowChanges;

for (int i = 0; i < obj.Fields.FieldCount; i++)
{
if (rowChanges.ValueChanged[i])

{
object oldValue = rowChanges.get_OriginalValue(i);
object newValue = obj.get_Value(i);


}
}
}

IFeatureChanges: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//0025000002qp000000



        IFeatureChanges featureChanges = obj as IFeatureChanges;

if (featureChanges != null && featureChanges.ShapeChanged)
{
// Do something
// featureChanges.OriginalShape
}

No comments:

Post a Comment