Select to view content in your preferred language

The map viewer is not initialized exception when opening attribute tables back to back

994
5
Jump to solution
01-02-2024 05:51 AM
TonyO
by
Emerging Contributor

 

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 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
NarelleChedzey
Esri Contributor

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

 

View solution in original post

5 Replies
GKmieliauskas
Esri Regular Contributor

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);

}

 

0 Kudos
TonyO
by
Emerging Contributor

@GKmieliauskas I had already tried this but the exception is same

0 Kudos
GKmieliauskas
Esri Regular Contributor

You must be on the UI thread to call OpenTablePane function.  Do not call it on MCT thread (in QueuedTask.Run).

0 Kudos
TonyO
by
Emerging Contributor

@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

0 Kudos
NarelleChedzey
Esri Contributor

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