This document is archived and information here might be outdated.  Recommended version.


ITOCControl2.SelectItem Method (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > Controls > ESRI ArcGIS Controls > Interfaces > IT > ITOCControl2 Interface > ITOCControl2.SelectItem Method
ArcGIS Developer Help

ITOCControl2.SelectItem Method

Sets the selected item in the TOCControl.

[Visual Basic .NET]
Public Sub SelectItem ( _
    ByVal Unk As Object, _
    [ByVal Data As Object] _
)
[C#]
public void SelectItem (
    object Unk,
    object Data
);
[C++]
HRESULT SelectItem(
  LPUNKNOWN Unk,
  VARIANT Data
);
[C++]
Parameters
Unk [in]

Unk is a parameter of type IUnknown Data [in, optional]
Data is a parameter of type VARIANT
To indicate this parameter is undefined pass in a VARIANT with type VT_ERROR and scode value of DISP_E_PARAMNOTFOUND.

Product Availability

Available with ArcGIS Engine.

Description

Selects the specified item in the TOCControl. The selected item will appear blue when the TOCControl has keyboard focus and grey when the TOCControl does not have keyboard focus.

Unk specifies an IMap object, and ILayer object or and ILegendGroup object.

Data specifies a long indicating the index of the legend class within the legend group. Use this index in conjunction with the legend group to obtain a particular legend class.

To select an ILegendGroup::Heading either just pass an ILegendGroup object or pass an ILegendGroup object with an index of -1. To select a legend class within the LegendGroup pass an ILegendGroup object with a valid index.

Errors Returned

1055 800a041f: A valid object is required for this property
1082 800a043a: The specified object could not be found

[C#]

//Selecting the focus map
axTOCControl1.SelectItem(axTOCControl1.ActiveView.FocusMap);

//Selecting a layer in the focus map
axTOCControl1.SelectItem(axTOCControl1.ActiveView.FocusMap.get_Layer(0));

//To select an item within a LegendGroup
ILayer layer = axTOCControl1.ActiveView.FocusMap.get_Layer(0);
ILegendInfo legendInfo = (ILegendInfo) layer;
ILegendGroup legendGroup = legendInfo.get_LegendGroup(0);
//Select a heading
axTOCControl1.SelectItem(legendGroup);
//Select a legend class
axTOCControl1.SelectItem(legendGroup, 2);
[Visual Basic .NET]

'Selecting the focus map
AxTOCControl1.SelectItem(AxTOCControl1.ActiveView.FocusMap)

'Selecting a layer in the focus map
AxTOCControl1.SelectItem(AxTOCControl1.ActiveView.FocusMap.Layer(0))

'To select an item within a LegendGroup
Dim player As ILayer
player = AxTOCControl1.ActiveView.FocusMap.Layer(0)
Dim legendInfo As ILegendInfo
legendInfo = player
Dim pLegendGroup As ILegendGroup
pLegendGroup = legendInfo.LegendGroup(0)
'Select a heading
AxTOCControl1.SelectItem(pLegendGroup)
'Select a legend class
AxTOCControl1.SelectItem(pLegendGroup, 2)

See Also

ITOCControl2 Interface

.NET Samples

Schematics Engine application Displaying a TOCControl context menu