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.
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.
This was very helpful, thank you. I was able to get it to work.