Hi,
I have a use case where I will have a list of layers for which I want to open the attribute table after those layers have already been added to the active map.
foreach (var layer in attributeTableLayers)
{
FrameworkApplication.Panes.OpenTablePane(layer, TableViewMode.eAllRecords);
}
The first layer's attribute table is opened but for the next, an exception is occurring
System.InvalidOperationException: 'The map viewer is not initialized.'
What is the best way to open attribute tables for multiple layers back-to-back?
@GKmieliauskas @Wolf @CharlesMacleod
Solved! Go to Solution.
Hi Tony,
The error message is a little misleading. But essentially before you open a table pane you must have a mapView active. Unfortunately once a table pane has been opened it becomes the active view. So the first table pane opens successfully, but then your mapView is no longer active which is why the second (and subsequent) attempts to open a table pane fail.
You should be able to open multiple table panes by code similar to the following
var mv = MapView.Active;
if (mv == null)
return;
// get the active pane (the pane of the active mapView)
var pane = FrameworkApplication.Panes.ActivePane;
foreach (var layer in attributeTableLayers)
{
try
{
// open a table pane
FrameworkApplication.Panes.OpenTablePane(layer, TableViewMode.eAllRecords);
// reactivate the pane for the mapview
pane.Activate();
}
catch (Exception ex)
{
}
}
Narelle
Hi,
I would recommend start from checking is it possible to open table pane for the layer:
foreach (var layer in attributeTableLayers)
{
if(FrameworkApplication.Panes.CanOpenTablePane(layer))
FrameworkApplication.Panes.OpenTablePane(layer, TableViewMode.eAllRecords);
}
@GKmieliauskas I had already tried this but the exception is same
You must be on the UI thread to call OpenTablePane function. Do not call it on MCT thread (in QueuedTask.Run).
@GKmieliauskas I am on Ui thread and not calling in MCT. Thats the reason first table is opened in the list. The issue is coming when in loop second table is trying to be opened as I mentioned in my question
Hi Tony,
The error message is a little misleading. But essentially before you open a table pane you must have a mapView active. Unfortunately once a table pane has been opened it becomes the active view. So the first table pane opens successfully, but then your mapView is no longer active which is why the second (and subsequent) attempts to open a table pane fail.
You should be able to open multiple table panes by code similar to the following
var mv = MapView.Active;
if (mv == null)
return;
// get the active pane (the pane of the active mapView)
var pane = FrameworkApplication.Panes.ActivePane;
foreach (var layer in attributeTableLayers)
{
try
{
// open a table pane
FrameworkApplication.Panes.OpenTablePane(layer, TableViewMode.eAllRecords);
// reactivate the pane for the mapview
pane.Activate();
}
catch (Exception ex)
{
}
}
Narelle