1

How do I handle the event when a user selects a feature from a feature layer in ArcObjects?

What I've tried:

    public ESRI.ArcGIS.Carto.IActiveViewEvents_SelectionChangedEventHandler m_ActiveViewEventsSelectionChanged;

    public ArcObjectsController()
    {
        ESRI.ArcGIS.Carto.IActiveViewEvents_Event activeViewEvents = (ESRI.ArcGIS.Carto.IActiveViewEvents_Event)ArcMap.Document.FocusMap;
        m_ActiveViewEventsSelectionChanged = new ESRI.ArcGIS.Carto.IActiveViewEvents_SelectionChangedEventHandler(OnActiveViewEventsSelectionChanged);
        activeViewEvents.SelectionChanged += m_ActiveViewEventsSelectionChanged;
    }

    public void OnActiveViewEventsSelectionChanged()
    {
        MessageBox.Show("Event Fired");
    }
  • 1
    Usually you don't wire events in the a constructor. see edndoc.esri.com/arcobjects/9.2/net/ViewCodePages/… – Kirk Kuykendall Aug 17 '16 at 19:10
  • That shouldn't be causing me not to be able to handle the event, it's still wired up correctly. – Dakota Hoch Aug 17 '16 at 19:18
  • If you wire it a Document's focused map, and then the focused map changes, then your handler won't get called. Likewise if the app opens a new or existing document, you'll need to re-wire your listener. Did you try it in a simple form, as shown in the example? – Kirk Kuykendall Aug 17 '16 at 19:23
  • Ahh, that makes sense.. I will try that and get back. – Dakota Hoch Aug 17 '16 at 19:28
  • I've found no problems wiring in the constructor for IEditEvents etc; if you want to offset your load wire them in your OnActivate and unwire in OnDeactivate (Important!). Did you let the IDE create the function for you? I had problems when I copy/pasted an event function and the IDE ignored it and wanted to create an Event2 function. Updated snippet (10.1 to 10.3) resources.arcgis.com/en/help/arcobjects-net/componenthelp/… – Michael Stimson Aug 17 '16 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.