Hello Juliet,Below is a very rudimentary way of comparing the value of one field in two selected features.You could call this method from a button click in a C# Add-In. If you are working in VBA or VB.NET then it will be a little different, but the interfaces used will be the same. Of course, replace the "YOUR_FIELDNAME" in the code with the actual field name.
public void PerformTest()
{
// Get the selection in TOC.
object item = ArcMap.Document.SelectedItem;
// Make sure it is a feature layer
if (item is IFeatureLayer)
{
IFeatureLayer featureLayer = item as IFeatureLayer;
IFeatureSelection featureSelection = featureLayer as IFeatureSelection;
ISelectionSet selectionSet = featureSelection.SelectionSet;
// Make sure exactly 2 features are selected
if (selectionSet.Count == 2)
{
// Get a cursor
ICursor cursor = null;
selectionSet.Search(null, true, out cursor);
// Get the index of the subject field
int fieldIdx = featureLayer.FeatureClass.FindField("YOUR_FIELDNAME");
// Typically you would cycle the rows of the cursor in a loop, but since
// we know we have exactly 2 rows to compare, just grab them.
// Set current row to first selected feature and get the field's value
IRow row = cursor.NextRow();
string value1 = row.get_Value(fieldIdx).ToString();
// Set current row to second selected feature and get the field's value
row = cursor.NextRow();
string value2 = row.get_Value(fieldIdx).ToString();
// Display the two values
MessageBox.Show("Feature 1: " + value1 +
"\nFeature 2: " + value2);
}
else
{
MessageBox.Show("Please select exactly 2 features.");
}
}
else
{
MessageBox.Show("Please select a feature layer.");
}
}