Select to view content in your preferred language

How to display attribute table with ArcGIS PRO SDK C#?

4266
5
Jump to solution
02-11-2020 02:18 PM
Amadeus111
Frequent Contributor

I would like to open the attribute table for a selected layer. I was able to create table from a feature layer and have access to it. However, I do not know how to put that into the display like right clicking on the layer and opening the attribute table. 

public void create_Layer()
{
   string shp_path = this.ComboBox_shps.Text;
   int indexNumber = 0;

   if (shp_path != null && shp_path != string.Empty)
      {
         System.Uri shp_filepath = new System.Uri(@shp_path);
         QueuedTask.Run(() =>
      {
   var shp_layer = LayerFactory.Instance.CreateLayer(shp_filepath, MapView.Active.Map, indexNumber,    shp_path.Substring(16));
   //Get the active map view.
   var mapView = MapView.Active;
   if (mapView == null)
      return Task.FromResult(false);
    else
   {
      var selectedLayer = mapView.GetSelectedLayers()[0];

      if (selectedLayer is ArcGIS.Desktop.Mapping.FeatureLayer)
         {
            ArcGIS.Core.Data.Table a_table = (selectedLayer as FeatureLayer).GetTable();
            int gugu = a_table.GetCount();
            MessageBox.Show(gugu.ToString()); // I can get the row count here 
         }

   //Zoom to the selected layers in the TOC
   return mapView.ZoomToAsync(selectedLayer);
      }
      });
   }
}

1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

Hi,

Here is a button OnClick method that opens the Attribute table for a layer:

protected override void OnClick()
    {
      var lyrs = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>();
      MapView.Active.SelectLayers(lyrs.ToList());

      var openTableBtnCmd = FrameworkApplication.GetPlugInWrapper("esri_editing_table_openTablePaneButton") as ICommand;

      if (openTableBtnCmd != null)
      {
        // Let ArcGIS Pro do the work for us
        if (openTableBtnCmd.CanExecute(null))
        {
          openTableBtnCmd.Execute(null);
        }
      }

    }

Thanks

Uma

View solution in original post

5 Replies
UmaHarano
Esri Regular Contributor

Hi

There are multiple ways to display the contents of your table. You can use a WPF Datagrid control to display the table.

Another option is to use the Pro SDK Table Control. Here is a sample that shows how to do that: 

TableControl Sample

Thanks

Uma

0 Kudos
Amadeus111
Frequent Contributor

Hi 

I tried TableControl Sample previously. It was giving an error :

Severity Code Description Project File Line Suppression State Error Could not load file or assembly 'ArcGIS.Desktop.DataGrid.Contrib.Wpf, Version=13.1.580.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86' or one of its dependencies. The system cannot find the file specified. TableControl TableControlDockpane.xaml 77

for creating table control

<editing:TableControl AutomationProperties.AutomationId="_tableControl" x:Name="tableControl"
Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
TableContent="{Binding Path=TableContent}"
RowContextMenu="{StaticResource MyRowContextMenu}"
SelectedRowContextMenu="{StaticResource MyRowContextMenu}"
>
</editing:TableControl>


I tried also using WPF Datagrid but could not figure it out. It tells I am calling the wrong thread.

ArcGIS.Core.Data.Table a_table = (selectedLayer as FeatureLayer).GetTable();

DataGrid_A_Table.DataContext = a_table; // I cann not pass pro table to Datagrid

I will check one more time. 

I even tried pressing hot keys (Ctrl + T) programmatically for selected layer but no luck either. 

I could not find the DAML ref ID for that button  either

I just would like to trigger to open attribute table like right clicking on the layer and click on the attribute table button. 

Thanks!

Oz

0 Kudos
UmaHarano
Esri Regular Contributor

Hi,

Here is a button OnClick method that opens the Attribute table for a layer:

protected override void OnClick()
    {
      var lyrs = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>();
      MapView.Active.SelectLayers(lyrs.ToList());

      var openTableBtnCmd = FrameworkApplication.GetPlugInWrapper("esri_editing_table_openTablePaneButton") as ICommand;

      if (openTableBtnCmd != null)
      {
        // Let ArcGIS Pro do the work for us
        if (openTableBtnCmd.CanExecute(null))
        {
          openTableBtnCmd.Execute(null);
        }
      }

    }

Thanks

Uma

Amadeus111
Frequent Contributor

Thank you for the response! I am busy with something else but I will try this ASAP and come back with results. 

Oz

0 Kudos
Amadeus111
Frequent Contributor

Perfect! It works now. 

Thank you for your help!

Oz

0 Kudos