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


Get Selected Table in Contents View Snippet (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference

Get Selected Table in Contents View Snippet

Returns a reference to the currently selected table in the given contents view.

[C#]
///<summary>Returns a reference to the currently selected table in the given contents view.</summary>
///  
///<param name="currentContentsView">An IContentsView interface.</param>
///  
///<returns>An ITable interface or Nothing if not found.</returns>
///   
///<remarks></remarks>
public ESRI.ArcGIS.Geodatabase.ITable GetSelectedTableInContentsView(ESRI.ArcGIS.ArcMapUI.IContentsView currentContentsView)
{
  if (currentContentsView != null && currentContentsView.SelectedItem is ESRI.ArcGIS.Geodatabase.ITable)
  {
    ESRI.ArcGIS.Geodatabase.ITable table=(ESRI.ArcGIS.Geodatabase.ITable)currentContentsView.SelectedItem;
    return table;
  }
  return null;
}
[Visual Basic .NET]
'''<summary>Returns a reference to the currently selected table in the given contents view.</summary>
'''  
'''<param name="currentContentsView">An IContentsView interface.</param>
'''  
'''<returns>An ITable interface or Nothing if not found.</returns>
'''   
'''<remarks></remarks>
Public Function GetSelectedTableInContentsView(ByVal currentContentsView As ESRI.ArcGIS.ArcMapUI.IContentsView) As ESRI.ArcGIS.Geodatabase.ITable

  If Not currentContentsView Is Nothing AndAlso TypeOf currentContentsView.SelectedItem Is ESRI.ArcGIS.Geodatabase.ITable Then
    Dim table As ESRI.ArcGIS.Geodatabase.ITable=CType(currentContentsView.SelectedItem, ESRI.ArcGIS.Geodatabase.ITable)
    Return table
  End If

  Return Nothing

End Function

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