<?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: IContentsView SelectedItem Enumerator in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/icontentsview-selecteditem-enumerator/m-p/384533#M10188</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Okay so the code above works to get an System.Object called 'x' right but then I didn't know what to do because it should have been IEnum or some such according to the documentation but it is type ISet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So using the code I wrote before first test to see whether it is of type ISet.&amp;nbsp; This is because other selected features can be included which makes it something else, can't recall off the top of my head what these other selected features might be but remember having the problem.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If it is of type ISet then it is probably just the selected ToC layers, which is what you want right?, though I have not looked into it to much so if it falls over it could be something I never encountered.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so some simple code is (in C#)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
System.Object x = contentsView.SelectedItem

if ((x is ESRI.ArcGIS.esriSystem.ISet))
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; ISet set = (ISet) x;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int numSelectedLyr = set.Count

&amp;nbsp;&amp;nbsp;&amp;nbsp; ...blah blah whatever code you want....

}
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think this may get a bit tricky with Group Layers also but haven't tried that so keep it in mind.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps.&amp;nbsp; If you're still confused post again and I will try to help you out with some better code or maybe a better explanation dependging on what you want.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 17:41:35 GMT</pubDate>
    <dc:creator>HenryColgate</dc:creator>
    <dc:date>2021-12-11T17:41:35Z</dc:date>
    <item>
      <title>IContentsView SelectedItem Enumerator</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/icontentsview-selecteditem-enumerator/m-p/384530#M10185</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to get a list of Layers selected in the Table of Contents.&amp;nbsp; That is they are highlighted whether they are checked on or off in the tick box.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I get the selected item and a single layer is selected in the ToC&amp;nbsp; the returned object is an ILayer.&amp;nbsp; However if more than one layer is selected it is not an IEnumLayer which I thought was logical and it is not a System.Array which seemed to be alluded to but not stated specifically.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is stated that the return value could be an enum but I don't know which Enum type to cast to.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the code below if multiple layers are selected in the ToC what is the type of object x?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;

IMxDocument mxDocument = (IMxDocument)ChangeMultipleSymbology_AddIn.ArcMap.Document;
IActiveView activeView = (IActiveView)mxDocument.ActiveView;
IContentsView contentsView = (IContentsView)mxDocument.CurrentContentsView;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
System.Object x = contentsView.SelectedItem;

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If there is a better way to get a list of values that are selected in the ToC I am open to suggestions.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Nov 2011 23:40:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/icontentsview-selecteditem-enumerator/m-p/384530#M10185</guid>
      <dc:creator>HenryColgate</dc:creator>
      <dc:date>2011-11-08T23:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: IContentsView SelectedItem Enumerator</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/icontentsview-selecteditem-enumerator/m-p/384531#M10186</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Answering my own question after searching the old forum again. Eventually I will port all of that knowledge over here and then ESRI can create a new forum so we have three to search.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The answer is it is an ESRI.ArcGIS.esriSystem.ISet &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;not&lt;/SPAN&gt;&lt;SPAN&gt; an enumerator that is named as such.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let's make the old forum searchable from here.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Nov 2011 00:03:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/icontentsview-selecteditem-enumerator/m-p/384531#M10186</guid>
      <dc:creator>HenryColgate</dc:creator>
      <dc:date>2011-11-09T00:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: IContentsView SelectedItem Enumerator</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/icontentsview-selecteditem-enumerator/m-p/384532#M10187</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Could you elaborate a bit more???&amp;nbsp;&amp;nbsp; I'm am trying to either determine the number of "selected" layers or clear them...&amp;nbsp; It sounds like what you found out will help me out some...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Kevin Orcutt&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2011 17:07:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/icontentsview-selecteditem-enumerator/m-p/384532#M10187</guid>
      <dc:creator>KevinOrcutt</dc:creator>
      <dc:date>2011-12-02T17:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: IContentsView SelectedItem Enumerator</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/icontentsview-selecteditem-enumerator/m-p/384533#M10188</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Okay so the code above works to get an System.Object called 'x' right but then I didn't know what to do because it should have been IEnum or some such according to the documentation but it is type ISet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So using the code I wrote before first test to see whether it is of type ISet.&amp;nbsp; This is because other selected features can be included which makes it something else, can't recall off the top of my head what these other selected features might be but remember having the problem.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If it is of type ISet then it is probably just the selected ToC layers, which is what you want right?, though I have not looked into it to much so if it falls over it could be something I never encountered.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so some simple code is (in C#)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
System.Object x = contentsView.SelectedItem

if ((x is ESRI.ArcGIS.esriSystem.ISet))
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; ISet set = (ISet) x;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int numSelectedLyr = set.Count

&amp;nbsp;&amp;nbsp;&amp;nbsp; ...blah blah whatever code you want....

}
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think this may get a bit tricky with Group Layers also but haven't tried that so keep it in mind.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps.&amp;nbsp; If you're still confused post again and I will try to help you out with some better code or maybe a better explanation dependging on what you want.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:41:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/icontentsview-selecteditem-enumerator/m-p/384533#M10188</guid>
      <dc:creator>HenryColgate</dc:creator>
      <dc:date>2021-12-11T17:41:35Z</dc:date>
    </item>
  </channel>
</rss>

