Modifying an existing feature
Editing existing features is performed by retrieving a row from a table, editing the row, then calling FeatureDataTable.SaveInFeatureSource(), FeatureSource.SaveEdits() or if you are using a FeatureDataReader you can call the Update method. When updating an existing feature, make a selection to determine the feature you want to update. The selection can be obtained by defining a QueryFilter, which may contain a spatial and attribute query component, then passing this as a parameter to the FeatureSource.GetDataTable method to obtain a FeatureDataTable for the selection or call FeatureSource.GetDataReader() to get back a DataReader. The SelectionMapAction can assist you by providing a graphic selection and returning a collection of FeatureDataTables. Using ADO calls, you can update the appropriate rows or access the geometry you wwant to update.
The following example shows how to change a value of selected features:
// Selects a specific cache layer
FeatureSource featureSource = mobileCache1.FeatureSource["parcels"] as FeatureSources;
// Checks if attributes are editable
if (!featureSource.AllowModify)
return;
// Query filter specifing feature IDs
QueryFilter queryFilter = new QueryFilter(new int[] { 5473, 14004, 13997, 7404, 8556, 10490, 16117 });
// Sets the initial parcel number
int apn = 100000000;
// Gets the position of the column to be edited
int apnFieldIndex = featureSource.Columns.IndexOf("APN");
// Using a feature datareader to update features
using (FeatureDataReader featureDataReader = featureSource.GetDataReader(queryFilter, null))
{
while(featureDataReader.Read())
{
// Gets the feature ID
int fid = featureDataReader.GetFid();
// Sets the parcel number
featureDataReader.SetString(apnFieldIndex, apn.ToString());
//Increments the parcel number
apn += 1;
// Prints info
System.Diagnostics.Debug.WriteLine("FID: " + fid + ", APN: " + featureDataReader.GetValue(apnFieldIndex));
// Updates the feature layer data table
featureDataReader.Update();
}
}