Deleting a feature

The process for deleting a feature is straightforward; you perform the normal edit environment set-up, select the feature, and delete them.

//make sure the proper 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;
  }
// 
FeatureDataTable selectedLayerDataTable = selectionMapAction1.SelectedFeatures[0]; 

foreach (FeatureDataRow selectedDataRow in selectedLayerDataTable.Rows) 
  {
  selectedDataRow.Delete(); 
  } 
// updates the feature layer data table
selectedLayerDataTable.SaveInFeatureLayer(); 
//clear selection
selectionMapAction1.SelectedFeatures.Clear(); 
}

Since this code will delete the feature from the local cache, it is typically used when a user needs to delete a feature they created in the field. If this actually was data pulled from the server, it will be necessary to post these changes back to the server. However, this should be a rare event, as most mobile applications do not allow features to be deleted from the database.


9/20/2011