Hello everybody,
I am using Get Selected Feature Layer In Contents View by following the sample code from ESRI:
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.
Anybody has any advice on this?
I am using arcmap and arcobjects 10.2.2 and vb.net arcmap add-in.
Thanks in advance.
Solved! Go to Solution.
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
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
Hi Duncan,
Thanks a lot!