Search code examples
vb.netlistboxarcgis

Use multiple selected items from listbox in WhereClause for ArcGis


I am able to select a single selected item in ArcGis using WhereClause. Currently I am working on the selection of multiple items and writing a WhereClause with these selected items.

My question is: how do I build a WhereClause with multiple items. Or; how do I populate a msgbox with multiple selected items? The multipleclause is the variable which I want to loop untill all items are used.

    Dim count As Integer = 0
    count = ListBox3.SelectedItems.Count
    If count = 0 Then
        MsgBox("Geen features geselecteerd")

    ElseIf count = 1 Then
        result = veld & "= '" & waarde & "'"
        MsgBox(result)

    Else
        firstclause = veld & "= '" & waarde & "'"
        For Each waarde In ListBox3.SelectedItems
            Do Until waarde Is Nothing
                multipleclause = " OR " & veld & "= '" & waarde & "'"
            Loop
        Next

        result = firstclause & multipleclause
        MsgBox(result)

    End If

Solution

  • This should get you started

    Dim count As Integer = 0
    count = ListBox3.SelectedItems.Count
    If count = 0 Then
        MsgBox("Geen features geselecteerd")
    
    ElseIf count = 1 Then
        result = veld & "= '" & waarde & "'"
        MsgBox(result)
    
    Else
        Dim sb as new System.Text.StringBuilder
        dim bFirst as Boolean = True
        For Each waarde In ListBox3.SelectedItems
            if bFirst Then
                bFirst = False
            else
                sb.append(" OR ")
            End If
            sb.Append(veld & "= '" & waarde & "'")
        Next
    
        result = sb.tostring
        MsgBox(result)
    
    End If