Select to view content in your preferred language

Editor not updating FeatureLayer after saving

1258
8
01-06-2011 12:30 PM
WilliamKimrey
Emerging Contributor
Hello all,

I've got an editor in my Silverlight program that is having trouble updating the featurelayer it's currently editing.

All other funtions are working like they should except for one thing.  I disabled the DeleteSelected button and replaced it with a method that flags a "REMOVED" field.  The MXD for that map has a Definition Query that only allows features where REMOVED IS NULL.  This method work fine, but when I hit the Save button, the feature is still there.

I've figured out that if I have an separate button that only updates the featurelayer, the feature goes away.  For whatever reason, the feature layer is not being updated when I save.  I've tried calling the FeatureLayer.Update in the EditCompleted event when the Action is "Save", but that doesn't work.

If it make a difference, I'm also using a FeatureDataForm to edit attributes.  When I hit my Remove button, I see the field populated so I know that it's working.  Does having the feature I'm editing in the FeatureDateForm cause any issues?  If not, then why does the FeatureLayer still keep it's graphics after I update it if it is even being updated.

Will
0 Kudos
8 Replies
AliMirzabeigi
Emerging Contributor
William,

Are you experiencing this issue even if you set the "DisableClientCaching" property of the FeatureLayer to TRUE?
0 Kudos
WilliamKimrey
Emerging Contributor
Yes,  DisableClientCaching has always been set to true.  Here's everything that's set on the FeatureLayer other than the ID and the URL.

DisableClientCaching = true
AutoSave = False
OutFields = *
Mode = OnDemand
Where = "OBJECTID = 0"

Now, when I select the layer to edit, the where clause is set to "" and the layer is updated so that I only see the features in the extent I'm currently working in for that specific layer.
0 Kudos
JenniferNery
Esri Regular Contributor
Can you subscribe to the layer's EndSaveEdits and SaveEditsFailed events to see if there had been any error saving the edit?

Are you saying the delete and save succeeds but the feature remains in your map?

All other funtions are working like they should except for one thing. I disabled the DeleteSelected button and replaced it with a method that flags a "REMOVED" field. The MXD for that map has a Definition Query that only allows features where REMOVED IS NULL. This method work fine, but when I hit the Save button, the feature is still there.


When you replaced DeleteSelected button, how are you deleting the feature exactly if the method you replaced it with only flags "Removed" field? I just want to know how the Save button can be enabled if you are performing the delete another way. Maybe the edit that it saves is a change in the attribute and not the delete of the feature. Could you share some code on how you are performing the delete? When you query the layer in the browser, the feature is in fact deleted but the map does not reflect this change?  Sorry I had more questions than answers 😛
0 Kudos
WilliamKimrey
Emerging Contributor
Don't feel bad about asking questions.  It's helping me to think through everything as well.

So, I should probably clarify that I'm not actually deleting a feature.  For whatever reason, the people above me decided that it was easier to flag a feature as "Removed" and filter it out instead of deleting it in case any information needed to be recovered.  So, when I "Delete" something, I'm really populating an attribute with the date and time the feature was removed.  The MXD that the was published to make this FeatureService has a Definition Query on the featureclass that filters out all features where this attribute is populated.

When I save after doing this, the featurelayer should update and in that update process filter out the removed feature because the "Removed" attribute is not populated.  This is not happening.

In the FeatureLayer's EndSaveEdits event, I see that the save is successful and has an updateresult.  However, the feature is still on the map and it's attributes are still in the FeatureDataForm.  I can force the featurelayer to update and clear the graphic, but that requires a second button and I can't make my users hit an "Update Layer" button after everytime they delete a feature.

So, what I need is a way to ensure that the featurelayer that I'm currently editing updates itself after I Save AND that it honors the Definition Query set in the MXD.


As for my code, I'm not using the editorwidget.  I have an Editor in my UserControl.Resources and a stackpanel who's datacontext is set to that editor.  I then have a row of buttons where the Commands are bound to the appropriate actions except for the Delete Button which has no command.  I'm using a Click event for that, but here's what I do in that event.

FeatureForm.GraphicSource.Attributes["REMOVED"] = DateTime.Now.ToString();
0 Kudos
JenniferNery
Esri Regular Contributor
Ah okay I think I get it now. The feature is not deleted but an attribute of it is set ("REMOVED" field gets a DateTime as string).
This means two things:
1 - The save is for saving the attribute value change. Save works 🙂
2 - The feature is not expected to be removed from the map unless you change the Where property of the FeatureLayer.
Maybe use the following where clause, because features that were not deleted will have this field null, right?
Where="REMOVED is null"
0 Kudos
WilliamKimrey
Emerging Contributor
You're right.  Features that have that attribute populated should be removed from the map because of the where clause.  The problem is, that's not happening.

During the EditCompleted event, I check to see if the EditAction was the Save Action.  If it is the Save Action, I set the FeatureLayer's Where clause to "Removed IS NULL" and then update the layer.

I created a button that does the same thing and it works just fine so I know that when I update the Featurelayer, the feature that has been flagged for removal will go away.

So, why is it that when I tell the featurelayer to update by using the button, everything works normally, but when i have it update during the EditCompleted event, there's no change?  That's my main problem here.  I want users to be able to remove a feature with 2 clicks.  One to populate the Removed attribute, and the other to save the changes.
0 Kudos
JenniferNery
Esri Regular Contributor
In your earlier post, you mentioned that the FeatureLayer has the following properties
DisableClientCaching = true 
AutoSave = False 
OutFields = * 
Mode = OnDemand 
Where = "OBJECTID = 0"


I meant to say update this Where clause to Where="REMOVED is null" so that you would not have to change it on Button Click. Since the value of this field is changing, you need to re-query the layer by calling Update() on EndSaveEdits.

An issue you might encounter by calling Update() inside EndSaveEdits event handler is that any attribute or geometry change, add or delete feature will re-query the layer. So maybe you can set a boolean when the attribute that changed is REMOVED.

For example:
  
private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
{
 removed = false;
 e.Graphic.AttributeValueChanged -= Graphic_AttributeValueChanged;
 this.MyFeatureDataForm.GraphicSource = e.Graphic;   
 e.Graphic.AttributeValueChanged += Graphic_AttributeValueChanged;
}
bool removed = false;
void Graphic_AttributeValueChanged(object sender,  Graphics.DictionaryChangedEventArgs e)
{
 if (e.Key == "REMOVED") removed = true;
}

private void FeatureLayer_EndSaveEdits(object sender, Tasks.EndEditEventArgs e)
{
 if (removed)
  (sender as FeatureLayer).Update();
}
0 Kudos
WilliamKimrey
Emerging Contributor
All right.  I've got it working.  It wasn't the Where clause that was causing the problem.  I did as you suggested and changed it to "Removed IS NULL" in the xaml, but was still not getting the desired result. 

However, I finally realized that you were talking about calling the Update function from the FeatureLayer's EndSaveEdits event.  I've been trying to get it to Update in the Editor's EditCompleted event.

Once I switched to the EndSaveEdits, it's working as intended.

Thank you very much for all the help.
0 Kudos