This document is archived and information here might be outdated. Recommended version. |
ArcObjects Help for .NET developers > ESRI.ArcGIS.Snippets > Snippets > Get Selected Feature Layer in Contents View Snippet (ArcObjects .NET 10.4 SDK) |
Returns a reference to the currently selected featurelayer in the given contents view.
///<summary>Returns a reference to the currently selected featurelayer in the given contents view.</summary> /// ///<param name="currentContentsView">An IContentsView interface.</param> /// ///<returns>An IFeatureLayer interface or Nothing if not found.</returns> /// ///<remarks></remarks> public ESRI.ArcGIS.Carto.IFeatureLayer GetSelectedFeatureLayerInContentsView(ESRI.ArcGIS.ArcMapUI.IContentsView currentContentsView) { if (currentContentsView != null && currentContentsView.SelectedItem is ESRI.ArcGIS.Carto.IFeatureLayer) { ESRI.ArcGIS.Carto.IFeatureLayer featureLayer=(ESRI.ArcGIS.Carto.IFeatureLayer)currentContentsView.SelectedItem; // Explicit Cast return featureLayer; } return null; }
'''<summary>Returns a reference to the currently selected featurelayer in the given contents view.</summary> ''' '''<param name="currentContentsView">An IContentsView interface.</param> ''' '''<returns>An IFeatureLayer interface or Nothing if not found.</returns> ''' '''<remarks></remarks> Public Function GetSelectedFeatureLayerInContentsView(ByVal currentContentsView As ESRI.ArcGIS.ArcMapUI.IContentsView) As ESRI.ArcGIS.Carto.IFeatureLayer If Not currentContentsView Is Nothing AndAlso TypeOf currentContentsView.SelectedItem Is ESRI.ArcGIS.Carto.IFeatureLayer Then Dim featureLayer As ESRI.ArcGIS.Carto.IFeatureLayer=CType(currentContentsView.SelectedItem, ESRI.ArcGIS.Carto.IFeatureLayer) ' Explicit Cast Return featureLayer End If Return Nothing End Function