3

Has anyone ever tried to get the number of layers that are selected in ArcMap? If I have a map document that has six layers and three of them are selected in the TOC, how does one count them using ArcObjects? I have looked for a while at IContentsView.SelectedItem. Documentation says it can be an enumerator, but I am having a hard time finding out actually what it's type is. In C#, if I do

string myType = IContentsView.SelectedItem.GetType().ToString();

myType is "System._ComObject". Not very descriptive... Trying

if(IContentsView.SelectedItem is IEnumLayer)

and similar checks has been unintuitive... I wasn't sure if multiple layers were selected that they would be stored in there but that was my first guess.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Mar 5, 2015 at 2:25
3

1 Answer 1

1

IContentsViewSelection should work for you.

http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//000v00000064000000

This is VB, but you should get the idea...

Dim pCVSel As IContentsViewSelection = My.ArcMap.Document.CurrentContentsView

Then: pCVSel.SelectedItems.Count will give you the count of selected items in the TOC.

answered Mar 5, 2015 at 18:04
1
  • Thanks, @Dan. This is probably cleaner than what I ended up doing. I looked at link and finally realized that SelectedItem is an ISet when it contains more than one object. I did the QI on that rather than on IContentsView. I will give you the answer though since you are correct. Thanks for your input! Commented Mar 6, 2015 at 2:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.