<?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 Fixing and updating selection layers with ArcObjects in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/fixing-and-updating-selection-layers-with/m-p/717754#M19119</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;I've two questions relating to updating layers in the ArcMap TOC.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;&lt;STRONG&gt;Question 1)&lt;/STRONG&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;I want to update a layer in the ArcMap TOC with a new selectionLayer of the same type.&amp;nbsp; I have the code to generate the selectionLayer (an IFeatureLayer), but as you will see below, I am currently adding this into the TOC as a new layer.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I’m creating a selection layer from a Feature Layer using &lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureLayerDefinition2&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af;"&gt;.CreateSelectionLayer().&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas;"&gt;The input FeatureLayer is a IGDBRasterCatalogLayer:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;ESRI.ArcGIS.Geodatabase.&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IRasterCatalog&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; rasterCatalog = &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;GeodatabaseUtilities&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.OpenFGDBRasterCatalog(Properties.&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Settings&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Default.pathToRasterCatalog, Properties.&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Settings&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Default.rasterCatalogName);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureClass&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; rasterCatFeatureClass = rasterCatalog &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;as&lt;/SPAN&gt; &lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureClass&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-left: 72pt; padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;ESRI.ArcGIS.Carto.&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IGdbRasterCatalogLayer&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; pGdbRastercatalogLayer = &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;new&lt;/SPAN&gt; &lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;GdbRasterCatalogLayerClass&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(); &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;pGdbRastercatalogLayer.Setup((&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ITable&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)rasterCatFeatureClass);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureSelection&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; featSelection = pGdbRastercatalogLayer &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;as&lt;/SPAN&gt; &lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureSelection&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;featSelection.SelectionSet = pSelectionset;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureLayerDefinition2&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; pFeatLayerDef2 = pGdbRastercatalogLayer &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;as&lt;/SPAN&gt; &lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureLayerDefinition2&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureLayer&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; selectionLayer = pFeatLayerDef2.CreateSelectionLayer(&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"Test"&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;true&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;""&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;""&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;selectionLayer.Name = layerName;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;This code works, and I can add the resulting Feature Layer (selectionLayer in above code) to the ArcMap TOC using:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;ESRI.ArcGIS.Carto.&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IMap&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; map = GetMapFromArcMap(&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ArcMap&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Application);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;map.AddLayer((&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ILayer&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)selectionLayer);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;Whilst this works, it would be far better to be able to assign the IFeatureLayer object &lt;SPAN style="text-decoration: underline;"&gt;to the existing &lt;/SPAN&gt;ILayer in the TOC, but I can’t see how.&amp;nbsp; It would be great if someone can indicate how to achieve this.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;&lt;STRONG&gt;Question 2)&lt;/STRONG&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;A separate but related question:&amp;nbsp; &lt;SPAN style="background: white;"&gt;If I fix a broken data source using the ArcMap UI on a selection layer, the selectionset persists.&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;When I try this with the following code, &lt;SPAN style="color: #000000; font-family: Consolas;"&gt;the layers data source is fixed, but all features from the new data source are returned, instead of just the selection set.&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-left: 36.0pt; margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureLayer&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; featureLayer = (&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureLayer&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)layerInTOC;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-left: 36.0pt; margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;// Change FeatureClass of layer&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; featureLayer.FeatureClass = newFeatureClass;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So it would be great to hear how to fix the selection layer data source and keep the selectionSet?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 10.0pt; font-family: 'Arial','sans-serif';"&gt;Environment:&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Arial','sans-serif';"&gt; ArcGIS Basic 10.2 desktop, Windows 7, C#, ArcObjects&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Arial','sans-serif';"&gt;Many thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Arial','sans-serif';"&gt;Dominic&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 Aug 2014 16:16:03 GMT</pubDate>
    <dc:creator>DominicRorke</dc:creator>
    <dc:date>2014-08-20T16:16:03Z</dc:date>
    <item>
      <title>Fixing and updating selection layers with ArcObjects</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/fixing-and-updating-selection-layers-with/m-p/717754#M19119</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;I've two questions relating to updating layers in the ArcMap TOC.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;&lt;STRONG&gt;Question 1)&lt;/STRONG&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;I want to update a layer in the ArcMap TOC with a new selectionLayer of the same type.&amp;nbsp; I have the code to generate the selectionLayer (an IFeatureLayer), but as you will see below, I am currently adding this into the TOC as a new layer.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I’m creating a selection layer from a Feature Layer using &lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureLayerDefinition2&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af;"&gt;.CreateSelectionLayer().&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas;"&gt;The input FeatureLayer is a IGDBRasterCatalogLayer:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;ESRI.ArcGIS.Geodatabase.&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IRasterCatalog&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; rasterCatalog = &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;GeodatabaseUtilities&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.OpenFGDBRasterCatalog(Properties.&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Settings&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Default.pathToRasterCatalog, Properties.&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;Settings&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Default.rasterCatalogName);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureClass&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; rasterCatFeatureClass = rasterCatalog &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;as&lt;/SPAN&gt; &lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureClass&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-left: 72pt; padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;ESRI.ArcGIS.Carto.&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IGdbRasterCatalogLayer&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; pGdbRastercatalogLayer = &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;new&lt;/SPAN&gt; &lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;GdbRasterCatalogLayerClass&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;(); &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;pGdbRastercatalogLayer.Setup((&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ITable&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)rasterCatFeatureClass);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureSelection&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; featSelection = pGdbRastercatalogLayer &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;as&lt;/SPAN&gt; &lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureSelection&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;featSelection.SelectionSet = pSelectionset;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureLayerDefinition2&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; pFeatLayerDef2 = pGdbRastercatalogLayer &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;as&lt;/SPAN&gt; &lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureLayerDefinition2&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureLayer&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; selectionLayer = pFeatLayerDef2.CreateSelectionLayer(&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;"Test"&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: blue; background: white;"&gt;true&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;""&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #a31515; background: white;"&gt;""&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;selectionLayer.Name = layerName;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;This code works, and I can add the resulting Feature Layer (selectionLayer in above code) to the ArcMap TOC using:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;ESRI.ArcGIS.Carto.&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IMap&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; map = GetMapFromArcMap(&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ArcMap&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;.Application);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;map.AddLayer((&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;ILayer&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)selectionLayer);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;Whilst this works, it would be far better to be able to assign the IFeatureLayer object &lt;SPAN style="text-decoration: underline;"&gt;to the existing &lt;/SPAN&gt;ILayer in the TOC, but I can’t see how.&amp;nbsp; It would be great if someone can indicate how to achieve this.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;&lt;STRONG&gt;Question 2)&lt;/STRONG&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;A separate but related question:&amp;nbsp; &lt;SPAN style="background: white;"&gt;If I fix a broken data source using the ArcMap UI on a selection layer, the selectionset persists.&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black;"&gt;When I try this with the following code, &lt;SPAN style="color: #000000; font-family: Consolas;"&gt;the layers data source is fixed, but all features from the new data source are returned, instead of just the selection set.&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-left: 36.0pt; margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureLayer&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt; featureLayer = (&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: #2b91af; background: white;"&gt;IFeatureLayer&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;)layerInTOC;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-left: 36.0pt; margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: green; background: white;"&gt;// Change FeatureClass of layer&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.5pt; font-family: Consolas; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; featureLayer.FeatureClass = newFeatureClass;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So it would be great to hear how to fix the selection layer data source and keep the selectionSet?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 10.0pt; font-family: 'Arial','sans-serif';"&gt;Environment:&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Arial','sans-serif';"&gt; ArcGIS Basic 10.2 desktop, Windows 7, C#, ArcObjects&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Arial','sans-serif';"&gt;Many thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Arial','sans-serif';"&gt;Dominic&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Aug 2014 16:16:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/fixing-and-updating-selection-layers-with/m-p/717754#M19119</guid>
      <dc:creator>DominicRorke</dc:creator>
      <dc:date>2014-08-20T16:16:03Z</dc:date>
    </item>
  </channel>
</rss>

