Select to view content in your preferred language

Edit mass Calculation field

1898
6
12-07-2011 07:10 AM
DavidAshton
Frequent Contributor
I have the editing tools (editor widget) up and running but I've been looking into a providing my end users a way to select several features (via spatial selection or attribute query) and do a mass attribute calculation.  I have the selection tools in place now I'm looking for examples, directions, and/or thoughts on how to allow my end users to assign a value to a certain field for all the selected features. 

Thanks
D
0 Kudos
6 Replies
DavidAshton
Frequent Contributor
Is there a way to take advantage of the FeatureData Grid to do this.  It seems like I can change the values in the FeatureData Grid Cells but can't save the changes.
0 Kudos
JenniferNery
Esri Regular Contributor
If you are using select tools from EditorWidget, you can subscribe to EditCompleted event.

private void EditorWidget_EditCompleted(object sender, Editor.EditEventArgs e)
{
 int total = 0;
 foreach (var edit in e.Edits)
 {
  if (edit.Graphic.Selected)
   total += (int)edit.Graphic.Attributes["ftype"];
 }
}


Or you can use FeatureLayer.PropertyChanged event. Note, however that this will be hit every time a graphic selection state changes.
private void FeatureLayer_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
 var l = sender as FeatureLayer;
 if (e.PropertyName == "SelectedGraphics")
 {
  var total = (from g in l.SelectedGraphics
      select (int)g.Attributes["ftype"]).Sum();
 }
}
0 Kudos
DavidAshton
Frequent Contributor
Jennifer thanks for the reply on both of my posts.  I think I have the other post handled (thanks to your suggestions 🙂 ) but I'm somewhat lost on this one.  I think when I used the word calculation you thought math and I was thinking more along the lines of the Field Calculator in ArcMap.  You make a selection and then can open the table to do a mass calculation on the selected records. 

My end users are needing to edit large volumns something like:
Select - FIELD1 is NULL
Update Selected Graphics/Records - FIELD1 = "6 inch"

I have built a Attribute Query editor and my users have the spatial query tools so I think I would like to user your second option

Once the selected graphics are retrieved and their attributes are returned to my FeatureDataGrid.  My thought was I would add a button to the featuredata grid.  When this button is clicked it would open a form that would give the user a text box and a submit button. Not entirely sure about how the form would layout and what would be included but I think I can handle all that: either way the users will be required to select a FIELD NAME and enter a Value.  This Value would then be populated into the field name of the selected records. 

This kind of leads me to my second question (2nd message in this post)
Is there a way to take advantage of the FeatureData Grid to do this. It seems like I can change the values in the FeatureData Grid Cells but can't save the changes.


Ever since I added the editing tools my end users and I can know change the values in the FeatureDataGrid (if the cell has a value already).  See my attachment - in the Agency field I add a bunch of random letter (jdkj ajdj .... ...).

Is there a way to allow these changes to happen (changes from the FeatureDataGRID)?


I'm unsure what field your code is trying to populate and with what value.  My question is can taking the code you provided


private void FeatureLayer_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
var l = sender as FeatureLayer;
if (e.PropertyName == "SelectedGraphics")
{
          var total = (from g in l.SelectedGraphics
   select (int)g.Attributes["ftype"]).Sum();
}
}


CAN I Do something with a standard button click?

private void ExcuteBatchUpdate_Click(object sender, RoutedEventArgs e)
        {
         
 
        }

 

Thanks for your help.
Dave
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You can use the FeatureDataGrid as a control allowing the user to select the features he needs to update.
But whatever the mean the user selects the features, why couldn't you just set the attribute in a loop on the selected features?
When you change an attribute of a feature, the featuredatagrid should automatically reflects this change.

Did I miss anything?
0 Kudos
DavidAshton
Frequent Contributor
DBroux, I think you nailed it.  I'm just unsure how to
why couldn't you just set the attribute in a loop on the selected features?

  
Is there an example out there that I can take a look at.  After I make the selection I'm having a hard time getting to the next step...setting the attribute on the selected set of features.

Thanks
Dave
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I think you nailed it. I'm just unsure how to


Something like:

void MassChange(IEnumerable<Graphic> graphics, string attName, object newValue)
{
  foreach(var g in graphics)
    g.Attributes[attName] = newValue;
}

then you can call MassChange either with the selected graphics of the layer:
               MassChange(graphicsLayer.SelectedGraphics, attName, newValue);
or with the selected graphics in the datagrid:
               MassChange(featureDataGrid.SelectedGraphics, attName, newValue);
or any list you populated by code:
               MassChange(myListOfGraphic, attName, newValue);
0 Kudos