Select to view content in your preferred language

Issues with Graphic::AttributeValueChanged

921
3
05-27-2011 02:14 AM
SanajyJadhav
Deactivated User
Hi all,

I have subscribed to AttributeValueChanged event of the Graphic of my editable feature layer.In this event, I want to the change the attribute value of another field.

I would clarify it bit more.Say, this event is fired for a field, VILLAGE_NAME.Then, in this event, I want to modify the value of another field, i.e. MIS_LINK of the same feature layer. I change it in my code and call FeatureLayer::SaveEdits().

But, the problem is, the value of another field, i.e. MIS_LINK is not getting changed.It is still the old value.Another thing that I noticed is, if I change the value of the same field (the field for which event was triggered), it is getting changed.

So, I am confused.Does this mean that we could alter the value of the field, only for which the event AttributeValueChanged gets triggered?

I would appreciate any help on this issue since this functionality is very important for integrity of our data. I have pasted my code below.

[PHP]  #region Village_Name

                //if user changes the Village_Name, then admin_code has to be changed accordingly.
                if (editFeatInfo.EditedFieldName.ToUpper() == "VILLAGE_NAME")
                {
                    //iterate thru the graphics collection and get the desired graphics
                    foreach (Graphic prclGraphics in prclsLyrGraphicList)
                    {
                        if (Convert.ToInt64(prclGraphics.Attributes["OBJECTID"]) == editFeatInfo.ObjectID)
                        {
                            clickedGraphicsForAttrEdit.AttributeValueChanged -= (clickedGraphicsForAttrEdit_AttributeValueChanged);

                            string adminCode = commConst.ADMIN_CODE_UNDEFINED;
                            string misLink = commConst.MIS_LINK_UNDEFINED;

                            //get the admin bndry code for this feature
                            if (prclGraphics.Attributes["ADMIN_BND_ID"] != null)
                            {
                                if (prclGraphics.Attributes["ADMIN_BND_ID"].ToString().Length > 0)
                                {
                                    adminCode = prclGraphics.Attributes["ADMIN_BND_ID"].ToString();
                                    misLink = adminCode + editFeatInfo.NewAttrValue;
                                    
                                   //THIS VALUE,I HAVETO CHANGE...
                                    prclGraphics.Attributes["MIS_LINK "] = misLink;
                                  
                                    break;
                                }
                            }
                        }
                    }
                    clickedGraphicsForAttrEdit.AttributeValueChanged += (clickedGraphicsForAttrEdit_AttributeValueChanged);
                    prclFeatLyr.SaveEdits();
                    return;
                }

                #endregion VIALLGe_NAME[/PHP]

Thanks,
Sanjay J.
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
I could not replicate the issue. I think that you may be subscribing to AttributeValueChanged more than once.

This is a short sample using: http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/FeatureServer/0
FeatureLayer l;
private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
{
 l = sender as FeatureLayer;
 e.Graphic.AttributeValueChanged += Graphic_AttributeValueChanged;
 var oldVal = (int)e.Graphic.Attributes[l.LayerInfo.TypeIdField];
 e.Graphic.Attributes[l.LayerInfo.TypeIdField] = oldVal == 0 ? 1 : 0;
 var affectedGraphicId = (int)e.Graphic.Attributes[l.LayerInfo.ObjectIdField];
}

void Graphic_AttributeValueChanged(object sender, ESRI.ArcGIS.Client.Graphics.DictionaryChangedEventArgs e)
{
 Graphic g = sender as Graphic;
 g.AttributeValueChanged -= Graphic_AttributeValueChanged;
 if (e.Key == "type")
 {
  g.Attributes["description"] = string.Format("Type was changed on {0} from {1} to {2}:", DateTime.UtcNow, e.OldValue, e.NewValue);
  l.SaveEdits();
 }
}


While debugging, keep note of the affectedGraphicId, you should find when you query the service that this graphic changed 2 properties (type and description).
0 Kudos
SanajyJadhav
Deactivated User
Ok.

So it seems that my logic is failing somewhere.I would look into it.

Thanks for the reply.
Sanjay.
0 Kudos
SanajyJadhav
Deactivated User
I found out the reason for this.It was rather very minor mistake.

I was copying field names from the REST interface and some how, white space was getting appended to the concerned field name.Thats why value was not getting saved.

Jenn:
Thanks for your help.

Regards,
Sanjay.
0 Kudos