ArcObjects Library Reference

Get Contents View from ArcMap Snippet

Get the Contents View (TOC) for ArcMap.

[C#]

///<summary>Get the Contents View (TOC) for ArcMap.</summary>
///
///<param name="application">An IApplication interface that is the ArcMap application.</param>
///<param name="index">A System.Int32 that is the tab number of the TOC. When specifying the index number: 0 = usually the Display tab, 1 = usually the Source tab.</param>
/// 
///<returns>An IContentsView interface.</returns>
/// 
///<remarks></remarks>
public ESRI.ArcGIS.ArcMapUI.IContentsView GetContentsViewFromArcMap(ESRI.ArcGIS.Framework.IApplication application, System.Int32 index)
{
  if (application == null || index < 0 || index > 1)
  {
    return null;
  }
  ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)(application.Document); // Explicit Cast
  ESRI.ArcGIS.ArcMapUI.IContentsView contentsView = mxDocument.get_ContentsView(index); // 0 = usually the Display tab, 1 = usually the Source tab

  return contentsView;
}
[Visual Basic .NET]

'''<summary>Get the Contents View (TOC) for ArcMap.</summary>
'''
'''<param name="application">An IApplication interface that is the ArcMap application.</param>
'''<param name="index">A System.Int32 that is the tab number of the TOC. When specifying the index number: 0 = usually the Display tab, 1 = usually the Source tab.</param>
''' 
'''<returns>An IContentsView interface.</returns>
''' 
'''<remarks></remarks>
Public Function GetContentsViewFromArcMap(ByVal application As ESRI.ArcGIS.Framework.IApplication, ByVal index As System.Int32) As ESRI.ArcGIS.ArcMapUI.IContentsView

  If application Is Nothing OrElse index < 0 OrElse index > 1 Then

    Return Nothing

  End If

  Dim mxDocument As ESRI.ArcGIS.ArcMapUI.IMxDocument = CType(application.Document, ESRI.ArcGIS.ArcMapUI.IMxDocument) ' Explicit Cast
  Dim contentsView As ESRI.ArcGIS.ArcMapUI.IContentsView = mxDocument.ContentsView(index) ' 0 = usually the Display tab, 1 = usually the Source tab

  Return contentsView

End Function


Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.ArcMapUI
  • ESRI.ArcGIS.Framework
  • ESRI.ArcGIS.System