ksarmiento

How to remove standalone table from contents

Discussion created by ksarmiento on Jan 28, 2020
Latest reply on Jan 29, 2020 by ksarmiento

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. 

Outcomes