This document is archived and information here might be outdated. Recommended version. |
ArcObjects Help for .NET developers > ESRI.ArcGIS.Snippets > Snippets > Get FeatureClass of Selected Feature Layer in Contents View Snippet (ArcObjects .NET 10.4 SDK) |
Returns a reference to the currently selected featureclass from the given contents view.
///<summary>Returns a reference to the currently selected featureclass from the given contents view.</summary> /// ///<param name="currentContentsView">An IContentsView interface.</param> /// ///<returns>An IFeatureClass interface or Nothing if not found.</returns> /// ///<remarks></remarks> public ESRI.ArcGIS.Geodatabase.IFeatureClass GetFeatureClassOfSelectedFeatureLayerInContentsView(ESRI.ArcGIS.ArcMapUI.IContentsView currentContentsView) { if (currentContentsView == null) { return null; } if (currentContentsView.SelectedItem is ESRI.ArcGIS.Carto.IFeatureLayer) { ESRI.ArcGIS.Carto.IFeatureLayer featureLayer=(ESRI.ArcGIS.Carto.IFeatureLayer)currentContentsView.SelectedItem; // Explicit Cast ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass=featureLayer.FeatureClass; return featureClass; } return null; }
'''<summary>Returns a reference to the currently selected featureclass from the given contents view.</summary> ''' '''<param name="currentContentsView">An IContentsView interface.</param> ''' '''<returns>An IFeatureClass interface or Nothing if not found.</returns> ''' '''<remarks></remarks> Public Function GetFeatureClassOfSelectedFeatureLayerInContentsView(ByVal currentContentsView As ESRI.ArcGIS.ArcMapUI.IContentsView) As ESRI.ArcGIS.Geodatabase.IFeatureClass If currentContentsView Is Nothing Then Return Nothing End If If 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 Dim featureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass=featureLayer.FeatureClass Return featureClass End If Return Nothing End Function