Grieck

Programmatic feature selection not showing the attribute list.

Discussion created by Grieck on Dec 18, 2010
Latest reply on Dec 29, 2010 by Grieck
Hello,

[ VS 2010, C#, ArcGIS 10 SP1, Personal GeoDatabase]

I'm trying to programmatically select a group of features on the map. I have four feature classes that participate in a group. The group membership is stored in a table: ID, ClassName, ClassOID. The user can select an item from the map and if it is part of the group the user can right click and choose "Select Group". This in turn queries the group table for all features that participate in the group and selects them on the map. I am able to get all the features in the group to successfully be selected on the map. The problem is they won't appear in the attributes window. However, if I manually select all the same features on the map the attributes for all the features appear in the attribute window.

What am I doing wrong in my selection process that allows the features to be selected on the map but won't allow me to see the attributes of the selected features?

public static void SelectMyID(int MyID)
{
  using (ComReleaser comReleaser = new ComReleaser())
  try
  {
 MyMap.ClearSelection();
 IFeatureWorkspace featworkspace = MyEditor3.EditWorkspace as IFeatureWorkspace;
 IQueryFilter2 queryfilter2 = new QueryFilterClass();
 queryfilter2.WhereClause = "ID = " + MyID;
 IFeatureClass featClass = null;
 ITable MyTable = featworkspace.OpenTable("MyTable");
 ICursor cur = MyTable.Search(queryfilter2, false);
 comReleaser.ManageLifetime(cur);  
 IRow row = null;
 while ((row = cur.NextRow()) != null)
 {
   featClass = featworkspace.OpenFeatureClass(row.get_Value((int)row.Fields.FindField("MyTable")).ToString());
   if (featClass != null)
   {
  switch (featClass.AliasName)
  {
    case "Feature1":
    case "Feature2":
    case "Feature3":
    case "Feature4":
   SelectFeature(featClass, (int)row.get_Value(row.Fields.FindField("ClassID")), 0, false, true);
   break;
  }
   }
 }
 MyFindCommandAndExecute("{FBF8C3FB-0480-11D2-8D21-080009EE4E51}", 1); //Zoom to selected
 MyMxDoc.ActiveView.Refresh();
  }
  catch (Exception ex)
  {
 MyRecordError(ex);
  }
}

public static void SelectFeature(IFeatureClass FC, int MyID, int AltID, bool ZoomTo, bool MultiSel)
{
 try
 {
  if(!MultiSel)
   MyMap.ClearSelection();
  IFeatureSelection vFeatSel = GetCurrentLayer(FC.AliasName, 0) as IFeatureSelection;
  if (vFeatSel == null)
   return;
  IQueryFilter2 queryfilt2 = new QueryFilterClass();
  if (AltID > 0)
   queryfilt2.WhereClause = "OtherID = " + AltID;
  else
   queryfilt2.WhereClause = "ClassID = " + MyID;
  if(MultiSel)
   vFeatSel.SelectFeaturesqueryfilt2, esriSelectionResultEnum.esriSelectionResultAdd, false);
  else
   vFeatSel.SelectFeatures(queryfilt2, esriSelectionResultEnum.esriSelectionResultNew, false);
  vFeatSel.SelectionChanged();

  if (ZoomTo)
   FindCommandAndExecute("{AB073B49-DE5E-11D1-AA80-00C04FA37860}", -1);//esriArcMapUI.ZoomToSelectedCommand
 }
 catch (Exception ex)
 {
  MyRecordError(ex);
 }
}
 
public static IFeatureLayer GetCurrentLayer(string sLayerName, int SubType)
{
 try
 {
  IFeatureLayer tempSetCurrentLayer;
  IEditLayers pEditLayers = MyEditor3 as IEditLayers;
  ESRI.ArcGIS.esriSystem.UID pID = new ESRI.ArcGIS.esriSystem.UIDClass();
  pID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; //IGeoFeatureLayer
  IEnumLayer pEnumLayer = MyMap.get_Layers(pID, true) as IEnumLayer;
  pEnumLayer.Reset();
  IGeoFeatureLayer pFL;
  while ((pFL = pEnumLayer.Next() as IGeoFeatureLayer) != null)
  {
   if (pFL.FeatureClass.AliasName.ToLower() == sLayerName.ToLower())
   {
    tempSetCurrentLayer = pFL as IGeoFeatureLayer;
    return tempSetCurrentLayer;
   }
  }
 }
 catch (Exception ex)
 {
  MyRecordError(ex, "Layer Name = " + sLayerName);
 }
 return null;
} 

Outcomes