I have a large program that pulls in various group layers and feature classes. What I am trying to do is check each feature class within a specific group layer that is empty. The count part is easy and just leaves the feat class unsourced. I really want to remove it when empty. This is a brief code example:
public static void FoiUpdSym()
{
IMxDocument MXDoc = (IMxDocument)PublicVars.g_App.Document;
IMap map = MXDoc.FocusMap;
IFeatureWorkspace SDEFeatWS = null;
IFeatureWorkspace SDEMasterWS = null;
IFeatureWorkspace FoiUpdateWS = null;
IGxLayer GxLayer;
IGxFile GxFile;
ILayer layer;
UID uid;
IEnumLayer enumLayer;
IFeatureLayer featLayer = null;
IFeatureClass featClass = null;
// load group layer file
GxLayer = new GxLayer();
GxFile = (IGxFile)GxLayer;
GxFile.Path = "\\\\gisTools\\gis\\symbology\\foiupdate\\foi-update_2016.lyr"; // strSymPath
GxLayer = (IGxLayer)GxFile;
layer = GxLayer.Layer;
map.AddLayer(layer);
uid = new UIDClass();
uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; // IFeatureLayer
enumLayer = map.get_Layers(uid, true);
layer = enumLayer.Next();
while (layer != null)
{
featLayer = (IFeatureLayer)layer;
if (Regex.IsMatch(layer.Name, "cityp_adds"))
{
try
{
featClass = FoiUpdateWS.OpenFeatureClass("cityp_adds");
IQueryFilter queryFilter = new QueryFilterClass();
if (featClass.FeatureCount(queryFilter) > 0)
{
featLayer.FeatureClass = featClass;
featLayer.Selectable = false;
featLayer.Visible = false;
}
else
{
map.DeleteLayer(featLayer);
}
}
catch { }
}
The else statement is what isn't working.