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


Get Selected Geodataset in Contents View Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

Get Selected Geodataset in Contents View Snippet

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

[C#]
///<summary>Returns a reference to the currently selected GeoDataset in the given contents view.</summary>
///  
///<param name="currentContentsView">An IContentsView interface.</param>
///  
///<returns>An IGeoDataset interface or Nothing if not found.</returns>
///   
///<remarks></remarks>
public ESRI.ArcGIS.Geodatabase.IGeoDataset GetSelectedGeodatasetInContentsView(ESRI.ArcGIS.ArcMapUI.IContentsView currentContentsView)
{
  if (currentContentsView != null && currentContentsView.SelectedItem is ESRI.ArcGIS.Geodatabase.IGeoDataset)
  {
    ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset=(ESRI.ArcGIS.Geodatabase.IGeoDataset)currentContentsView.SelectedItem; // Explicit Cast

    return geoDataset;
  }
  return null;
}
[Visual Basic .NET]
'''<summary>Returns a reference to the currently selected GeoDataset in the given contents view.</summary>
'''  
'''<param name="currentContentsView">An IContentsView interface.</param>
'''  
'''<returns>An IGeoDataset interface or Nothing if not found.</returns>
'''   
'''<remarks></remarks>
Public Function GetSelectedGeodatasetInContentsView(ByVal currentContentsView As ESRI.ArcGIS.ArcMapUI.IContentsView) As ESRI.ArcGIS.Geodatabase.IGeoDataset

  If Not currentContentsView Is Nothing AndAlso TypeOf currentContentsView.SelectedItem Is ESRI.ArcGIS.Geodatabase.IGeoDataset Then
    Dim geoDataset As ESRI.ArcGIS.Geodatabase.IGeoDataset=CType(currentContentsView.SelectedItem, ESRI.ArcGIS.Geodatabase.IGeoDataset) ' Explicit Cast

    Return geoDataset

  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.Geodatabase