Deleting a feature

The process for deleting a feature is straightforward; you perform the normal edit environment setup, select one or more features, and delete them.

//make sure the correct feature is selected
 // if no feature selected, return 
if (selectionMapAction1.SelectedFeatures == null || selectionMapAction1.SelectedFeatures.Count == 0) 
  { 
    MessageBox.Show("You must select a feature to delete"); 
    return;
  }
// for this sample code features to delete are hardwired to be from first datatable
FeatureDataTable selectedLayerDataTable = selectionMapAction1.SelectedFeatures[0]; 

foreach (FeatureDataRow selectedDataRow in selectedLayerDataTable.Rows)
  {
    selectedDataRow.Delete(); 
  } 

// updates the feature layer data table
selectedLayerDataTable.SaveInFeatureSource(); 

//clear selection
selectionMapAction1.SelectedFeatures.Clear(); 
}

The code snippet above only marks features as deleted in a local cache on the device. The change will be made to the back-end database after the cache is synchronized with the server or through a geoprocessing tool. Since this code deletes the feature from the local cache, it is typically used when you need to delete a feature you created in the field. If this actually was data pulled from the server, it would be necessary to post the changes back to the server. However, this is a rare event, as most mobile applications do not provide the functionality to delete features from the GIS database.

1/7/2015