Retrieve field values from selected row(s) in TableControl

348
3
Jump to solution
02-07-2021 12:33 PM
ThomasBecker1
Occasional Contributor II

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?

0 Kudos
1 Solution

Accepted Solutions
ThomasBecker1
Occasional Contributor II

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?

View solution in original post

0 Kudos
3 Replies
ThomasBecker1
Occasional Contributor II

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?

View solution in original post

0 Kudos
FredericPoliart_EsriAU
New Contributor II

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"];
   }
}


ThomasBecker1
Occasional Contributor II

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

Thanks Frederic