Detect one or more rows selected in an attribute table from an add-in

1771
2
Jump to solution
03-16-2020 11:27 AM
JustinMartinek
Occasional Contributor

With ArcGIS Pro SDK 2.5, you can detect that the map selection has changed with the MapSelectionChangedEvent, which also includes selecting one or many rows in the attribute table of a geodatabase that is loaded in a MapView. I know that I can wire it up like:

private SubscriptionToken eventToken = null;

private void SetupEvents()
{
eventToken = MapSelectionChangedEvent.Subscribe(OnMapSelectionChangedEvent);
}
private void OnMapSelectionChangedEvent(MapSelectionChangedEventArgs obj)
{
//do work on the selection
}


I would prefer to isolate the work in the handler to only happen when the geodatabase's attribute table row selection changes, not on all map selections. I haven't been able to find an event that fits this qualification in the sdk. Does one exist?

EDIT 3/19/2020:  Since it may be unclear what I'm attempting to achieve, the below image has the MapView and the open attribute table.  I would like for the selection of a row in that table to trigger an event in my add-in.  The MapSelectionChangedEvent is far too broad for this purpose, so if there is a SelectionChanged event or the like on the attribute table that I can hook into, that would work.  I cannot seem to find one, though.  I can select something from the add-in and have it show on the map, but I wanted to know if something existed on this built in control.

0 Kudos
1 Solution

Accepted Solutions
JustinMartinek
Occasional Contributor

After contacting ESRI Support, there is no way to actually achieve this through a singular event, but you can do them in tandem.

The suggested approach was:

private SubscriptionToken eventToken = null;

private void SetupPaneEvent()
{
    eventToken = ActivePaneChangedEvent.Subscribe(OnActivePaneChangedEvent);
}

private void OnActivePaneChangedEvent(PaneEventArgs args)
{

   //The window that is selected is a table, so then register an event that handles selections
    if (FrameworkApplication.Panes.ActivePane is ITablePane)
    {
        eventToken = MapSelectionChangedEvent.Subscribe(OnMapSelectionChangedEvent);
    }
    else
    {

   // not a table?  Unsubscribe.
        MapSelectionChangedEvent.Unsubscribe(eventToken);
    }
}

private void OnMapSelectionChangedEvent(MapSelectionChangedEventArgs args)
{

   //Do work that detects which source and how you need to filter out different actions between feature classes

   //and stand alone tables
}

View solution in original post

2 Replies
JustinMartinek
Occasional Contributor

After contacting ESRI Support, there is no way to actually achieve this through a singular event, but you can do them in tandem.

The suggested approach was:

private SubscriptionToken eventToken = null;

private void SetupPaneEvent()
{
    eventToken = ActivePaneChangedEvent.Subscribe(OnActivePaneChangedEvent);
}

private void OnActivePaneChangedEvent(PaneEventArgs args)
{

   //The window that is selected is a table, so then register an event that handles selections
    if (FrameworkApplication.Panes.ActivePane is ITablePane)
    {
        eventToken = MapSelectionChangedEvent.Subscribe(OnMapSelectionChangedEvent);
    }
    else
    {

   // not a table?  Unsubscribe.
        MapSelectionChangedEvent.Unsubscribe(eventToken);
    }
}

private void OnMapSelectionChangedEvent(MapSelectionChangedEventArgs args)
{

   //Do work that detects which source and how you need to filter out different actions between feature classes

   //and stand alone tables
}

jmidtlyng
Occasional Contributor

Did you ever run into GC issues and need to use keepSubscriberAlive like mentioned in the following ticket?

https://community.esri.com/t5/arcgis-pro-sdk-questions/sketchcompletedevent-firing-only-sometimes/m-...

I'm using your approach and everything seems to be working well whether or not I use keepSubscriberAlive but maybe my tests aren't rigorous enough.

0 Kudos