How to make a query from selection??

2124
2
04-14-2016 01:10 AM
JanPohle
New Contributor

Hey Everyone,

I need your help. It´s about VB.net. How can I make a new query from already selected Features?

So far I managed to fill a listbox with the information of the first categorie (e.g. State). Now I want to click on one of the categories to fill another listbox with information about the second categorie (e.g. Postcode). The Table is the same. It just needs to change the row and fill the second listbox. How do I get that?

I´m new to programming with VB.net so please explain as simple as possible! 😉

Thanks for your help!!

Public Sub New()

        InitializeComponent()

        Dim pTable As ITable

        Dim intLayer As Integer

        pMxDoc = My.ArcMap.Application.Document

        pMap = pMxDoc.FocusMap

        pActiveView = pMap

      

        intLayer = mod_state.findLayerByName("S6", pMap)

        If intLayer = -1 Then

            MsgBox("There is no layer!")

            Exit Sub

        End If

        pFeatureLayer = pMap.Layer(intLayer)

        pTable = pFeatureLayer

        Dim pTableSort As ITableSort = New TableSort

        With pTableSort

            .Table = pTable

            .Fields = "state"

            .Ascending("state") = True

            .CaseSensitive("state") = True

End With

        pTableSort.Sort(Nothing)

   pCursor = pTableSort.Rows

        Dim pRow As IRow

        pRow = pCursor.NextRow

        Dim strState As String

        strState = ""

        Me.lst_state_ID.Items.Clear()

        Do While Not pRow Is Nothing

            If (pRow.Value(22) <> strstrState) Then

             strState = pRow.Value(22)

                Me.lst_KAT_ID.Items.Add(strState)

            End If

            pRow = pCursor.NextRow

        Loop

End Sub

Private Sub lst_state_ID_Click(sender As System.Object, e As System.EventArgs) Handles lst_state_ID.Click

        Dim pActiveView As IActiveView

        Dim pFeatureSelection As IFeatureSelection

        Dim pQueryFilter As IQueryFilter

        Dim intLayer As Integer

        pMxDoc = My.ArcMap.Application.Document

        pMap = pMxDoc.FocusMap

        pActiveView = pMap

      

        intLayer = mod_state.findLayerByName("S6", pMap)

    

        If intLayer = -1 Then

            MsgBox("There is no Layer!")

            Exit Sub

        End If

        pFeatureLayer = pMap.Layer(intLayer)

        pFeatureSelection = pFeatureLayer

       pQueryFilter = New QueryFilter

        pQueryFilter.WhereClause = "State = '" & Me.lst_state_ID.SelectedItem &  "'"

        pFeatureSelection.Clear()

        pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, False

        pActiveView.Refresh()

    End Sub

0 Kudos
2 Replies
WesMiller
Regular Contributor III

You may want to move your question to the Developers​ group

0 Kudos
KenBuja
MVP Esteemed Contributor

In the SelectFeatures method, you have the choice of esriSelectionResultEnum ​to use. Currently, you're using esriSelectionResultNew, but to select from the current selection, you have to use esriSelectionResultAnd

0 Kudos