There might be a better solution for this but i would do it like that:
private IEditor editor;
private IWorkspace workspace;
private IFeatureLayer featLayer;
private void DeleteFeatures(IFeatureLayer featLayer)
{
//if there is already a selection on feature layer you can get all selected features
IFeatureSelection featureSelection = featLayer as IFeatureSelection;
ISelectionSet selectionSet = featureSelection.SelectionSet;
ICursor cursor;
//in search method you can use QueryFilter to query features or you can use 'null' and you will get all features in layer
selectionSet.Search(null, false, out cursor);
IRow row = cursor.NextRow();
editor.StartEditing(workspace);
while (row != null)
{
row.Delete();
row = cursor.NextRow();
}
editor.StopEditing(true);
}
Now to obtain editor from ArcMap:
private void GetEditor()
{
UID uidEditor = new UIDClass();
uidEditor.Value = "esriEditor.Editor";
editor = ArcMap.Application.FindExtensionByCLSID(uidEditor) as IEditor;
}
To get workspace I would do sth like this:
private void GetFileWorkspace(IFeatureLayer featLayer)
{
IFeatureDataset featDataset = featLayer.FeatureClass.FeatureDataset;
IFeatureWorkspace featWorkspace = (IFeatureWorkspace)featDataset.Workspace;
workspace = (IWorkspace)featWorkspace;
}
Now you need feature layer:
private void GetMapLayers()
{
uid.Value = "{40A9E885-5533-11D0-98BE-00805F7CED21}";
IEnumLayer enumLayerByName = map.get_Layers((UID)uid, true);
enumLayerByName.Reset();
ILayer iLayer = enumLayerByName.Next();
while (!(iLayer == null))
{
switch (iLayer.Name)
{
case "YourLayerName":
featLayer = (IFeatureLayer)iLayer;
break;
.........(more cases)
default:
break;
}
}
}
Good luck!MDruzgala