GDB_Browser Form

578
2
05-04-2011 02:14 AM
shivagugila
New Contributor III
Greetings,

Can some one help me with required corrections to my code.

I want to design a form with 4 listboxs. Listbox1 displays Dataset name, Listbox2 displays FC list of selected dataset,Listbox3 with Field names of selected FC and Listbox4 -unique values of selected field. Also Intend to create some command buttons.

1. Unable to get all the dataset names in listbox1(there are total of 6 DS)
2. Code lines to get the list in Listbox2 from selected item of Listbox1.

Code in halfway:


Private Sub UserForm_Initialize()


    Dim pMxdoc As IMxDocument
    Dim pApp As IApplication
    Set pApp = application
    Set pMxdoc = pApp.Document
    Dim pLayer As ILayer
    Dim pDataLayer As IDataLayer
    Dim pDatasetName As IDatasetName
    Dim pWSName As IWorkspaceName
    Dim sFDS As String
    Dim pFCName As IFeatureClassName
    Dim i As Integer
     Dim j As Integer
    For i = 0 To pMxdoc.FocusMap.LayerCount - 1
        Set pLayer = pMxdoc.FocusMap.layer(i)
        If TypeOf pLayer Is IDataLayer Then
            'sFDS = ""
           
           
            Set pDataLayer = pMxdoc.FocusMap.layer(i)
            Set pDatasetName = pDataLayer.DataSourceName
            Set pWSName = pDatasetName.WorkspaceName
           
           
            If TypeOf pDatasetName Is IFeatureClassName Then
            Set pFCName = pDatasetName
            If Not pFCName.FeatureDatasetName Is Nothing Then
            sFDS = pFCName.FeatureDatasetName.name
            End If
            End If
           
                   
           For j = 0 To ListBox1.ListCount - 1
           If ListBox1.List(j) = pFCName.FeatureDatasetName.name Then
           bDuplicate = True
           End If
           Next
           If bDuplicate = False Then
        ListBox1.AddItem sFDS

Dim pUID As New UID
pUID = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" 'IGeoFeatureLayer IID
Dim pEnumLayer As IEnumLayer
Set pEnumLayer = pMxdoc.FocusMap.Layers(pUID, True)


Set pDataLayer = pEnumLayer.Next

           End If
          
           'ListBox1.AddItem sFDS
           ListBox2.AddItem pDatasetName.name
End If
Next i




Thanks in advance.
shiva
0 Kudos
2 Replies
sujaygarapati
New Contributor
Below is the code, i hope it will helpful


Public Class pAttributeQuery
    Private m_pmapcontrol As IMapControl2

#Region "Private Variables"
    Private _strExpression As String
    'Private _aryFieldNames As Array
    Private _strPrimaryField As String
#End Region

#Region "Public Events"
    Public Event ExpressionChanged(ByVal sender As Object, ByVal e As ExpressionChangeEventArgs)
#End Region

    Public Sub pAttributeQuery_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'im plnam As String = PlyrName.SelectedIndex
        For i As Integer = 0 To GTZform.AxMapControl1.LayerCount - 1

            Dim play As ILayer = GTZform.AxMapControl1.get_Layer(i)

            PlyrName.Items.Add(play.Name)
            PlyrName.SelectedIndex = 0

        Next



    End Sub
 



    Private Sub PlyrName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlyrName.SelectedIndexChanged

        Dim plyr As ILayer = GTZform.AxMapControl1.get_Layer(PlyrName.SelectedIndex)
        Dim plyrFil As ILayerFields
        plyrFil = plyr
        pID.Items.Clear()
        Dim ii As Integer
        For ii = 0 To plyrFil.FieldCount - 1
            Dim pfield As IField = plyrFil.Field(ii)

            pID.Items.Add(pfield.Name)

        Next

    End Sub

    Private Sub pID_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pID.SelectedIndexChanged

        Dim fl As IFeatureLayer = GTZform.AxMapControl1.get_Layer(PlyrName.SelectedIndex)
        Dim il As ILayerFields = fl

        Dim i As Long
        i = il.FindField(pID.SelectedItem)
        pIDFieldEXP.Items.Clear()

        Dim fcc As IFeatureCursor = fl.Search(Nothing, False)

        Dim ff As IFeature = fcc.NextFeature

        Do Until ff Is Nothing
            pIDFieldEXP.Items.Add(ff.Value(i))
            ff = fcc.NextFeature
        Loop
    End Sub
    Private Sub AddFieldToExpression(ByVal strField As String)
        Dim strExpression As String = txtExpression.Text.Trim

        'If strExpression = "" Then
        '    _strExpression = """" + strField.Trim + """" + ""
        'Else
        '    _strExpression = _strExpression + " & "" "" & """"" + strField.Trim + """" + ""
        'End If

        txtExpression.Text = _strExpression
        '"OBJECTID" & " " & [Shape_Length]
    End Sub


    Private Sub pID_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles pID.DoubleClick
        AddFieldToExpression(pID.SelectedItem.ToString)
    End Sub
    Private Sub pIDFieldEXP_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles pIDFieldEXP.DoubleClick
        'AddFieldToExpression(pIDFieldEXP.SelectedItem.ToString)
        txtExpression.Text = txtExpression.Text + pIDFieldEXP.SelectedItem.ToString
    End Sub
 
  
    Private Sub pClean_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'txtExpression.Text = ""
        'AddFieldToExpression(_strPrimaryField)
    End Sub

   

    Private Sub pCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pCancel.Click
        Me.Dispose()
    End Sub

    Private Sub pApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pApply.Click
     

        Dim pEQuearyRes As String = txtExpression.Text
        Dim pfeaturelayer As ESRI.ArcGIS.Carto.IFeatureLayer

        pfeaturelayer = GTZform.AxMapControl1.get_Layer(PlyrName.SelectedIndex)
        GTZform.AxMapControl1.Refresh()
        Dim pfeatureclass As ESRI.ArcGIS.Geodatabase.IFeatureClass = pfeaturelayer.FeatureClass

        'If pfeaturelayer IsNot Nothing Then
        Dim pQuerfilter As ESRI.ArcGIS.Geodatabase.IQueryFilter = New ESRI.ArcGIS.Geodatabase.QueryFilterClass()
        pQuerfilter.WhereClause = pEQuearyRes
        Dim pfeatureselection As ESRI.ArcGIS.Carto.IFeatureSelection = TryCast(pfeaturelayer, ESRI.ArcGIS.Carto.IFeatureSelection) 'directcast
        pfeatureselection.SelectFeatures(pQuerfilter, esriSelectionResultEnum.esriSelectionResultNew, False)

        ' End If

        If pfeatureclass.FeatureCount(pQuerfilter) = Nothing Then
            MessageBox.Show("No Items Selected")
        Else
            MessageBox.Show("No of  Selected Items : " & pfeatureclass.FeatureCount(pQuerfilter))

        End If
        GTZform.AxMapControl1.ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)





    End Sub

   
End Class
Public Class ExpressionChangeEventArgs
    Inherits System.EventArgs

    '' add local member variable to hold point label plcement angles
    Private _strExpression As String

    '' class constructor
    Public Sub New(ByVal strExpression As String)
        Me._strExpression = strExpression
    End Sub

    '' Return Expression
    Public ReadOnly Property Expression() As String
        Get
            Return _strExpression
        End Get
    End Property
End Class
0 Kudos
shivagugila
New Contributor III
Thanks sujay.

BTW,  i want to use this form in Arcmap, so thought of excluding the dataset list in listbox1. now the listbox1 contains FC  list.
(I am using arcgis 9.2, VBA)

Regards,
shiva
0 Kudos