ISelectionEvents pSelEvents; pSelEvents = myMap as ISelectionEvents; pSelEvents.SelectionChanged();
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("{AB073B49-DE5E-11D1-AA80-00C04FA37860}", -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 { ESRI.ArcGIS.esriSystem.UID pID = new ESRI.ArcGIS.esriSystem.UIDClass(); pID.Value = "{40A9E885-5533-11D0-98BE-00805F7CED21}";// IFeatureLayer IMap myMap = myMxDoc.Activeview.FocusMap as IMap; IEnumLayer pEnumLayer = MyMap.get_Layers(pID, true) as IEnumLayer; pEnumLayer.Reset(); IFeatureLayer pFL; while ((pFL = pEnumLayer.Next() as IFeatureLayer) != null) { if (pFL.FeatureClass.AliasName.ToLower() == sLayerName.ToLower()) { return pFL; } } } catch (Exception ex) { MyRecordError(ex, "Layer Name = " + sLayerName); } return null; }
Venkat and Sherry,Thank you so much for responding to my thread. Everything you have said is true and is what I am currently doing. I was afraid I had something seriously wrong in my code. However, it appears the way I am selecting data is correct. Venka, I'm using your suggestion to make sure the layer is selectable, visible, editable. Sherry, I saw the IFeatureSelection example and implemented it pretty much as provided.But, what is weird is the first time I call my selection routine, via command button, it selects all the correct data and displays the selected data correctly in the attribute window. But then if I try a new selection sending it through the same code it selects the data but won't allow it to appear in the attribute window. I physically have to stop and restart ArcMap to get it to select and display the data in the attribute window.What I'm trying to do is select several different feature classes on the map programmatically, but also have those selected features appear in the attribute window. It is similar to using the select by rectangle and having the attribute window refresh itself each time a selection changes. Would either of you have time to confirm or test this behavior to see if you can reproduce it? Is there something else I need to do to refresh the attribute window?Greg
Hello,How do I select several features from several different feature classes at one time? I know which features I want to select from within the separate feature classes. So, how do I put that together to perform a selection?Once I have all of the features selected do I need to do something special to get them to show up in the attribute editor window? I'm trying to select several different spatial objects and have each one appear in the attribute editor window like it does if I were to manually draw a selection rectangle around several objects on the map.Is this a BUG? Does anyone have any sample code that allows the programmatic selection of several spatial features and have those same features appear in the attribute editor window? Can anyone else reproduce this problem?Greg
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.