Can someone help me please, I'm searching for a way to highlight a Feature Class in the TOC. I tried so many snippets and I didn't get the result I wanted

So what I'd like to have is a function written in vb.net in which I pass a string that is the name of the Feature Class that shall be highlighted with this blue rectangle, basically just like when a user would make a selection in the TOC


1 Answer 1


Have you tried setting the SelectedItem from IContentsView interface? Something like:

Dim pTOC As IContentsView = pMxDoc.ContentsView(0)
pTOC.SelectedItem = pLayerToSelect

The 0 represents display view, other numbers might work for different TOC views (e.g. source view, catalog view...)

To iterate through your layers in the TOC, you can do it the way I've written out below, or you can use an enumeration (IEnumLayer). The code belows loops through all TOC layers and shows their names in a messagebox.

Dim pMap As IMap = pMxDoc.FocusMap
Dim pLayer As ILayer 
For i As Integer = 0 to pMap.LayerCount - 1
    pLayer = pMap.Layer(i)

Also, to access a layers feature class, just use pLayer.FeatureClass

  • seems to work like a charm, though I need to figure out how to iterate through the layers FCs
    – kitty
    Commented Sep 25, 2014 at 13:50
  • @kitty - I've updated my answer to show you how to iterate through layers
    – pvdev
    Commented Sep 25, 2014 at 14:38
  • grazie mille, Icoursey :)
    – kitty
    Commented Sep 25, 2014 at 16:16
  • di niente @kitty :)
    – pvdev
    Commented Sep 25, 2014 at 16:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.