vb.net arcobjects select a layer

3471
2
Jump to solution
10-13-2014 12:02 AM
LiYao
by
New Contributor III

Hello everybody,

I am using Get Selected Feature Layer In Contents View by following the sample code from ESRI:

ArcObjects 10 .NET SDK Help

But sometimes there is no layer selected, which cause error in the application.

I tried to find the way to select a layer through arcobjects (as in the following picture), but no luck.

nnnnnnnnnnnnnnnnnnnnn.jpg

Anybody has any advice on this?

I am using arcmap and arcobjects 10.2.2 and vb.net arcmap add-in.

Thanks in advance.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

Li,

You say you have used the snippet to get the selected layer but then you say you want to select it?

The VBA code below shows how to set a layer to be the selected layer in the TOC

Public Sub SetLayerToBeSelected()

    Dim pMXD As IMxDocument

    Set pMXD = ThisDocument

      

    Dim pLayer As ILayer

    Set pLayer = pMXD.FocusMap.Layer(2) ' tree is zero-based so this is 3rd layer

  

    Dim pContentsView As IContentsView

    Set pContentsView = pMXD.ContentsView(0)

    pContentsView.SelectedItem = pLayer

    pMXD.UpdateContents

End Sub

View solution in original post

0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor

Li,

You say you have used the snippet to get the selected layer but then you say you want to select it?

The VBA code below shows how to set a layer to be the selected layer in the TOC

Public Sub SetLayerToBeSelected()

    Dim pMXD As IMxDocument

    Set pMXD = ThisDocument

      

    Dim pLayer As ILayer

    Set pLayer = pMXD.FocusMap.Layer(2) ' tree is zero-based so this is 3rd layer

  

    Dim pContentsView As IContentsView

    Set pContentsView = pMXD.ContentsView(0)

    pContentsView.SelectedItem = pLayer

    pMXD.UpdateContents

End Sub

0 Kudos
LiYao
by
New Contributor III

Hi Duncan,

Thanks a lot!

0 Kudos