In this example, I have a form with two comboboxes. The first (cboPointLayer) contains the point layers in the view and the second (cboField) contains the fields of the selected layer. The Form_Initialize function populates cboPointLayer and when the user selects a layer, the subroutine cboPointLayer_SelectedIndexChanged populates cboField.
Public Class SelectionForm
Private m_App As ESRI.ArcGIS.Framework.IApplication
Private pMxDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument
Private pEnumLayers As ESRI.ArcGIS.Carto.IEnumLayer
Private pFLayer As ESRI.ArcGIS.Carto.IFeatureLayer
Friend Function Form_Initialize(ByVal m_application As ESRI.ArcGIS.Framework.IApplication) As Boolean
Dim pLayer As ESRI.ArcGIS.Carto.ILayer
Dim pFLayer As ESRI.ArcGIS.Carto.IFeatureLayer2
m_App = m_application
pMxDoc = CType(m_App.Document, ESRI.ArcGIS.ArcMapUI.IMxDocument)
cboPointLayer.Items.Clear()
cboField.Items.Clear()
If pMxDoc.FocusMap.LayerCount > 0 Then
pEnumLayers = pMxDoc.FocusMap.Layers
pLayer = pEnumLayers.Next
Do Until pLayer Is Nothing
If pLayer.Valid Then
If TypeOf pLayer Is ESRI.ArcGIS.Carto.IFeatureLayer Then
pFLayer = pLayer
If pFLayer.ShapeType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint Then
cboPointLayer.Items.Add(pLayer.Name)
End If
End If
End If
pLayer = pEnumLayers.Next
Loop
End If
Return True
End Function
Private Sub cboPointLayer_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPointLayer.SelectedIndexChanged
Dim pLayer As ESRI.ArcGIS.Carto.ILayer
Dim pFields As ESRI.ArcGIS.Geodatabase.IFields
Try
pEnumLayers.Reset()
cboField.Items.Clear()
pLayer = pEnumLayers.Next
Do Until pLayer Is Nothing
If pLayer.Name = cboPointLayer.Text Then
pPointFLayer = New ESRI.ArcGIS.Carto.FeatureLayer
pPointFLayer = pLayer
Exit Do
End If
pLayer = pEnumLayers.Next
Loop
pFields = pPointFLayer.FeatureClass.Fields
For i As Integer = 0 To pFields.FieldCount - 1
If pFields.Field(i).Type < 6 Then 'this adds only numeric, date, and string fields, not geometry, Blobs, raster, GUID, Global ID, or XML fields.
cboField.Items.Add(pFields.Field(i).Name)
ListBox1.Items.Add(pFields.Field(i).Name)
End If
Next
EnableRun()
Catch ex As Exception
Messagebox.Show(ex.message, "Point Layer")
End Try
End Sub
End Class