Select to view content in your preferred language

How do I save a graphic selected from one feature layer to another feature layer

824
4
03-25-2011 08:46 AM
MuralidharMoka
Emerging Contributor
Hi.

I have two similar  feature layers f and fmh .
f has some features  and fmh is empty.
Now I select a graphic from f  and then want to add that to fmh.

I am doing it like this.
  void f_MouseLeftButtonUp(object sender, ESRI.ArcGIS.Client.GraphicMouseButtonEventArgs e)

        {
            Graphic SelectedGraphic= e.Graphic;
               fmh.Graphics.Add(SelectedGraphic);  //I get an error here
               fmh.Update();   //is this right
       }


I get an error like this 
"Specified argument was out of the range of valid values.\r\nParameter name: Cannot add graphic to multiple graphiclayers"

Can any one help me with this.
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
One graphic can't be added to 2 graphics layers.

So you have to create a new graphic.

Something like:

 
var newGraphic = new Graphic { Symbol = oldGraphic.Symbol, Geometry = Geometry.Clone(oldGraphic.Geometry), Attributes = oldGraphic.Attributes };
0 Kudos
MuralidharMoka
Emerging Contributor
Hi Dominique
Thank you for the reply.
I trying to write code like this

Graphic g= new Graphic()
                                  {
                                     Symbol = selectedGraphic.Symbol,
                                     Geometry = selectedGraphic.Geometry, //I did not find clone so is this right
                                    Attributes = selectedGraphic.Attributes //gives an error at compile time
                                  }

Error: Property or indexer 'Attributes' cannot be assigned to -- it is read only
0 Kudos
DominiqueBroux
Esri Frequent Contributor

Error: Property or indexer 'Attributes' cannot be assigned to -- it is read only


You right. I forgot that.

You have to add the attribute one by one:
 
Graphic g= new Graphic()
{
Symbol = selectedGraphic.Symbol,
Geometry = selectedGraphic.Geometry, //I did not find clone so is this right
}

foreach (var kvp in selectedGraphic.Attributes)
{
        g.Attributes.Add(kvp);
}
0 Kudos
MuralidharMoka
Emerging Contributor
Thanks very much. This really helped me.
Great support.
Muralidhar Moka
0 Kudos