<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Error in displaying/highlighting selected graphics .... in ArcGIS Viewer for Silverlight Questions</title>
    <link>https://community.esri.com/t5/arcgis-viewer-for-silverlight-questions/error-in-displaying-highlighting-selected-graphics/m-p/369411#M1078</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;A graphic can only be associated with one layer. You have to clone your graphic object and then add it to your layer.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Graphic clonedGraphic = new Graphic
{ 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Symbol = yourOldGraphic.Symbol,
&amp;nbsp;&amp;nbsp;&amp;nbsp; Geometry = Geometry.Clone(yourOldGraphic.Geometry),
};

foreach (var attribute in yourOldGraphic.Attributes)
&amp;nbsp;&amp;nbsp;&amp;nbsp; clonedGraphic.Attributes.Add(attribute);

layer.Graphics.Add(clonedGraphic);
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a lot for the reply, but it seems that I couldn't make it work.&amp;nbsp; The following code works fine except &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for the mentioned error at either one of these two lines:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; //flashPointGraphicsLayer.Graphics.Add(thisgraphic);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; //flashPointGraphicsLayer.Graphics.Insert(0,thisgraphic);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If I comment them out, the MyMap pans correctly as different record is selected.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;private HighlightCorrespondingPointOnMapForSelectedRecord()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//Below is a record selected/hightlighted in the DataGrid table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Graphic thisgraphic = (Graphic)FindDetailsDataGridOHI.SelectedItem;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if (thisgraphic != null )&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; thisgraphic.Symbol = LayoutRoot.Resources["flashPointRenderer"] as ESRI.ArcGIS.Client.Symbols.Symbol;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; thisgraphic.Geometry.SpatialReference = MyMap.SpatialReference;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GraphicsLayer flashPointGraphicsLayer = MyMap.Layers["transitionPointGraphicTemp"] as GraphicsLayer;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; flashPointGraphicsLayer.ClearGraphics();&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //flashPointGraphicsLayer.Graphics.Add(thisgraphic);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //flashPointGraphicsLayer.Graphics.Insert(0,thisgraphic);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyMap.PanTo(thisgraphic.Geometry);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 17:07:55 GMT</pubDate>
    <dc:creator>YurongTan</dc:creator>
    <dc:date>2021-12-11T17:07:55Z</dc:date>
    <item>
      <title>Error in displaying/highlighting selected graphics ....</title>
      <link>https://community.esri.com/t5/arcgis-viewer-for-silverlight-questions/error-in-displaying-highlighting-selected-graphics/m-p/369409#M1076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I getting an error for the following and have no clue what it means.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error is a run time error: "Speficied argument was out of the range of valid values.&amp;nbsp; Parameter name: Graphic is already associated with another layer."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error points to this line:&amp;nbsp;&amp;nbsp; graphicsLayerTEMP.Graphics.Insert(0, thisgraphic);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance for any help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;private void FindDetailsDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DataGrid dataGrid = sender as DataGrid;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; int selectedIndex = dataGrid.SelectedIndex;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Graphic thisgraphic = (Graphic)FindDetailsDataGridOHI.SelectedItem;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; if (selectedIndex &amp;gt; -1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thisgraphic.Symbol = LayoutRoot.Resources["griddataPointRendererTEMP"] as ESRI.ArcGIS.Client.Symbols.Symbol;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; // GridDataSelectedGraphicTEMP is a separate graphic layer just to highlight the selected point&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; GraphicsLayer graphicsLayerTEMP = MyMap.Layers["GridDataSelectedGraphicTEMP"] as GraphicsLayer;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; thisgraphic.Geometry.SpatialReference = MyMap.SpatialReference;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; graphicsLayerTEMP.ClearGraphics();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; graphicsLayerTEMP.Graphics.Insert(0, thisgraphic);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; if ( myCursorAt == "TABLE" )&amp;nbsp; MyMap.PanTo(graphicsLayerTEMP.FullExtent.Extent);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2013 14:30:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-viewer-for-silverlight-questions/error-in-displaying-highlighting-selected-graphics/m-p/369409#M1076</guid>
      <dc:creator>YurongTan</dc:creator>
      <dc:date>2013-02-20T14:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: Error in displaying/highlighting selected graphics ....</title>
      <link>https://community.esri.com/t5/arcgis-viewer-for-silverlight-questions/error-in-displaying-highlighting-selected-graphics/m-p/369410#M1077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;A graphic can only be associated with one layer. You have to clone your graphic object and then add it to your layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Graphic clonedGraphic = new Graphic
{ 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Symbol = yourOldGraphic.Symbol,
&amp;nbsp;&amp;nbsp;&amp;nbsp; Geometry = Geometry.Clone(yourOldGraphic.Geometry),
};

foreach (var attribute in yourOldGraphic.Attributes)
&amp;nbsp;&amp;nbsp;&amp;nbsp; clonedGraphic.Attributes.Add(attribute);

layer.Graphics.Add(clonedGraphic);
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:07:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-viewer-for-silverlight-questions/error-in-displaying-highlighting-selected-graphics/m-p/369410#M1077</guid>
      <dc:creator>JohanCarlsson</dc:creator>
      <dc:date>2021-12-11T17:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Error in displaying/highlighting selected graphics ....</title>
      <link>https://community.esri.com/t5/arcgis-viewer-for-silverlight-questions/error-in-displaying-highlighting-selected-graphics/m-p/369411#M1078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;A graphic can only be associated with one layer. You have to clone your graphic object and then add it to your layer.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Graphic clonedGraphic = new Graphic
{ 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Symbol = yourOldGraphic.Symbol,
&amp;nbsp;&amp;nbsp;&amp;nbsp; Geometry = Geometry.Clone(yourOldGraphic.Geometry),
};

foreach (var attribute in yourOldGraphic.Attributes)
&amp;nbsp;&amp;nbsp;&amp;nbsp; clonedGraphic.Attributes.Add(attribute);

layer.Graphics.Add(clonedGraphic);
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a lot for the reply, but it seems that I couldn't make it work.&amp;nbsp; The following code works fine except &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for the mentioned error at either one of these two lines:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; //flashPointGraphicsLayer.Graphics.Add(thisgraphic);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; //flashPointGraphicsLayer.Graphics.Insert(0,thisgraphic);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If I comment them out, the MyMap pans correctly as different record is selected.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;private HighlightCorrespondingPointOnMapForSelectedRecord()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//Below is a record selected/hightlighted in the DataGrid table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Graphic thisgraphic = (Graphic)FindDetailsDataGridOHI.SelectedItem;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if (thisgraphic != null )&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; thisgraphic.Symbol = LayoutRoot.Resources["flashPointRenderer"] as ESRI.ArcGIS.Client.Symbols.Symbol;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; thisgraphic.Geometry.SpatialReference = MyMap.SpatialReference;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GraphicsLayer flashPointGraphicsLayer = MyMap.Layers["transitionPointGraphicTemp"] as GraphicsLayer;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; flashPointGraphicsLayer.ClearGraphics();&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //flashPointGraphicsLayer.Graphics.Add(thisgraphic);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //flashPointGraphicsLayer.Graphics.Insert(0,thisgraphic);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyMap.PanTo(thisgraphic.Geometry);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:07:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-viewer-for-silverlight-questions/error-in-displaying-highlighting-selected-graphics/m-p/369411#M1078</guid>
      <dc:creator>YurongTan</dc:creator>
      <dc:date>2021-12-11T17:07:55Z</dc:date>
    </item>
  </channel>
</rss>

