Select to view content in your preferred language

Why is Editor.Change.Graphic null when Editorwidget saves?

605
1
01-20-2011 09:42 AM
KirkKuykendall
Deactivated User
I've got a featurelayer with a definition query set up where Expiration_date is null.

When someone saves a feature with a non-null expiration date, I'd like for the graphic to disappear.

In the EditCompleted eventhandler however, the graphic is null.  Is this a bug?

private void OnSaveFeatures(Editor.EditEventArgs e)
{
    FeatureLayer fLayer = null;
    foreach (Editor.Change c in e.Edits)
    {
        if (c.Layer.ID.ToUpper() == "ProjectPolys".ToUpper())
        {
            fLayer = c.Layer as FeatureLayer;
            if (c.Graphic != null)
            {
                if (c.Graphic.Attributes.ContainsKey("Expiration_Date"))
                {
                    if (c.Graphic.Attributes["Expiration_Date"] != null)
                        ((FeatureLayer)c.Layer).Graphics.Remove(c.Graphic);
                }
            }
            else
                Debug.WriteLine("null graphic!");
        }
    }
    if (fLayer != null)
        fLayer.Update(); // this is a workaround
}
0 Kudos
1 Reply
JenniferNery
Esri Regular Contributor
Thank you for your post. We'll consider this for future enhancement. For the meantime, you can subscribe to the layer's EndSaveEdits and maybe do the following:
private void FeatureLayer_EndSaveEdits(object sender, EndEditEventArgs e)
{
 if(e.Results== null|| e.Results.UpdateResults == null) return;
 FeatureLayer layer = sender as FeatureLayer;
 foreach (var item in e.Results.UpdateResults)
 {
  Graphic graphic = layer.Graphics.Where(g =>(int) g.Attributes[layer.LayerInfo.ObjectIdField] ==(int) item.ObjectID).First();
  //TODO: your code goes here
 }
}
0 Kudos