Select to view content in your preferred language

Retrieve field values from selected row(s) in TableControl

2060
3
Jump to solution
02-07-2021 12:33 PM
TomGeo
by
Frequent Contributor

I want to retrieve all, or just some value(s) from a selected row, or multiple, in a TableControl.

Meaning, on click of a button the TableControl is checked for selected rows and based on the result a couple of values, or the values from all fields should be returned.

How can I do that?

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
0 Kudos
1 Solution

Accepted Solutions
TomGeo
by
Frequent Contributor

I think I found a way, but I am not certain it's the correct one.

  1. get the selected object id(s) from the TableControl
  2. check the existence of the requested fields, and get their index values
  3. iterate over the selected object id(s), while feeding an Inspector
    1. LoadAsync(MapMember, ObjectID)
    2. Inspector[FieldIndex] to get the field value

Is that as it should be, or do I overcomplicate things?

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!

View solution in original post

0 Kudos
3 Replies
TomGeo
by
Frequent Contributor

I think I found a way, but I am not certain it's the correct one.

  1. get the selected object id(s) from the TableControl
  2. check the existence of the requested fields, and get their index values
  3. iterate over the selected object id(s), while feeding an Inspector
    1. LoadAsync(MapMember, ObjectID)
    2. Inspector[FieldIndex] to get the field value

Is that as it should be, or do I overcomplicate things?

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
0 Kudos
FredericPoliart_EsriAU
Frequent Contributor

get the selected features into a list with:
var selectedFeatures = ArcGIS.Desktop.Mapping.MapView.Active.Map.GetSelection();

Then iterate through each (it will give you 3 iterations if you have selected features within 3 layers, even if more than 1 item is selected within a layer)

foreach (var selection in selectedFeatures)
{
  var inspector = new ArcGIS.Desktop.Editing.Attributes.Inspector();
  // The inspector will contain an array of layers (with 1 or more feature in each)
  inspector.Load(selection.Key, selection.Value);
  foreach (long oneObjectId in selection.Value)
   {      var inInsp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
         inInsp.Load(selection.Key, oneObjectId);
         //you can now use mystring=inInsp["STREETNAME"];
   }
}


TomGeo
by
Frequent Contributor

So, the way I was describing before is the way to go.

Thanks Frederic

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!