How to remove standalone table from contents

929
2
01-28-2020 04:20 PM
KhamilleJaynes
New Contributor III

Hello! I am trying to remove a specified standalone table from the Contents pane. Here is the code I have so far:

try
{
     var mapView = MapView.Active;
     if (mapView != null)
     {
          var map = mapView.Map;
          if (map != null)
          {
               foreach (StandaloneTable table in map.StandaloneTables)
               {
                    if (table.Name.Contains("K Factors"))
                       map.RemoveStandaloneTable(table);
               }
          }
     }
}
catch (Exception ex)
{
}

There may be multiple tables whose name contains "K Factors" and that's ok -- I would like them all removed. 

I noticed that map.StandaloneTables is a ReadOnlyObservableCollection and I'm not sure if this has to do with the exceptions that I'm getting.

The exception says either, {"Class not registered\r\n\r\nClass not registered\r\n"} or {"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"}

Any help would be appreciated. 

0 Kudos
2 Replies
RichRuh
Esri Regular Contributor

The RemoveStandaloneTable() method must be called on the MCT.  Try this:

QueuedTask.Run(()=>
{
  map.RemoveStandaloneTable(table);
}

See Working with Multithreading in ArcGIS Pro for more information.

KhamilleJaynes
New Contributor III

This was very helpful, thank you. I was able to get it to work. 

0 Kudos