problem with comboboxes when selection of value in first combobox fill values in second combobox but every second change is without error

Viewed 27

using selectionchanged event on combobox to fill values for second combobox but every second select in first combobox ends with error from second combobox using data from mysql, filling values item.tag and item.content for each item in combobox

Try
    values = New Dictionary(Of String, String) From {
            {"SQL", "SELECT id_kontakt,kont_ime FROM vlado_Dtrans.lok_kontakt where id_lokacija=" + CInt((CType(naro_CB_gradbisca.SelectedItem, ComboBoxItem)).Tag).ToString},
            {"PARAM", ""}
            }

    content = New FormUrlEncodedContent(values)
    httpClient = New HttpClient()
    myTask = httpClient.PostAsync("https://dtrans.zcloud.systems/api/prcSQL.php", content)
    myTask.Wait()
    result = myTask.Result.Content.ReadAsStringAsync()
    result.Wait()
    myRes = result.Result
    Dim dt_lok As DataTable = CType(JsonConvert.DeserializeObject(myRes, GetType(DataTable)), DataTable)
    v_lok = ""

    indeks = 0
    indxs = 0
    Dim stevc = naro_CB_gr_kontakt.Items.Count
    naro_CB_gr_kontakt.Items.Clear()

    'MsgBox(stevc)
    If stevc > 0 Then
        For n = 1 To stevc
            naro_CB_gr_kontakt.Items.RemoveAt(n - 1)
        Next
    End If
    If dt_lok.Rows.Count > 0 Then
        naro_TB_kontakt_obstaja.Text = "1"

        For Each row As DataRow In dt_lok.Rows

            Dim item2 As ComboBoxItem = New ComboBoxItem()

            item2.Content = row.Item(1).ToString
            item2.Tag = row.Item(0).ToString
            'MsgBox(item2.Tag.ToString & "#" & item2.Content.ToString)
            'If stevc = indeks And stevc > 0 Then
            'naro_CB_gr_kontakt.Items.Item(indeks) = item2
            'Else
            naro_CB_gr_kontakt.Items.Add(item2)
            'End If
            If row.Item(0).ToString = v_lok Then
                indxs = indeks
            End If
            indeks += 1
        Next
        'Nar_CBLokacija.Items.Add("0#Lokacija je enaka naslovu naročnika")

        If naro_CB_gr_kontakt.Items.Count > 0 Then
            naro_CB_gr_kontakt.SelectedIndex = indxs
        End If
    End If

    'Nar_TBkontaktGSM.Text = ""

    Catch ex As Exception
    MessageBox.Show("Kontakti:" & ex.Message)
End Try
0 Answers
Related