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."); } }
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.