[GIS] Getting feature class names within dataset with vb.net and ArcObjects

arcobjectsvb.netvisual studio

I am totally new to arcobjects. I want to get the feature class names withın a dataset and add them to a listbox. I was able to get the dataset names but i do not know how to iterate through the feature class names within these datasets.

Public Sub GetWorkspace()

    Dim pEnumGxObj As ESRI.ArcGIS.Catalog.IEnumGxObject
    Dim pFCFilter As New ESRI.ArcGIS.Catalog.GxFilterWorkspaces
    Dim pGxDatabase As ESRI.ArcGIS.Catalog.IGxDatabase2
    Dim pGxDialog As New ESRI.ArcGIS.CatalogUI.GxDialog
    Dim pGxObject As ESRI.ArcGIS.Catalog.IGxObject
    Dim pWorkspace As ESRI.ArcGIS.Geodatabase.IWorkspace

    pGxDialog.ObjectFilter = pFCFilter

    If Not pGxDialog.DoModalOpen(My.ArcMap.Application.hWnd, pEnumGxObj) Then Exit Sub

    pGxObject = pEnumGxObj.Next

    If pGxObject Is Nothing Then Exit Sub
    Try
        If TypeOf pGxObject Is ESRI.ArcGIS.Catalog.IGxDatabase2 Then
            pGxDatabase = pGxObject
            pWorkspace = pGxDatabase.Workspace
            System.Windows.Forms.MessageBox.Show(pWorkspace.PathName)
        Else
            System.Windows.Forms.MessageBox.Show("This is likely a shapefile workspace")
        End If


        Dim pEnumDSName = pWorkspace.DatasetNames(esriDatasetType.esriDTAny)


        Dim pSdeDSName = pEnumDSName.Next
        While Not pSdeDSName Is Nothing
            ListBox1.Items.Add(pSdeDSName.Name)
            pSdeDSName = pEnumDSName.Next
        End While


    Catch ex As Exception
        System.Windows.Forms.MessageBox.Show(ex.ToString, "GetWorkspace")

    End Try
End Sub

Best Answer

You need to iterate the datasets to get his containing feature classes. Like this:

While Not pSdeDSName Is Nothing
    Dim pEnumDataset = pSdeDSName.Subsets
    Dim pSubset = pEnumDataset.Next()
    While Not pSubset Is Nothing
        If pSubset.Type = ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass Then
            ListBox1.Items.Add(pSubset.Name)
        End If
    End While
End While

The code is not tested, I'm used to C#, but you get the idea.

Related Question