How to change ComboBox data source?

I have two comboboxes. Sorting data combobox1 is a fixed row list. The combobox2 data combination will be a list of strings, which depends on the choice of combobox1. This is very similar to the usual case as follows: first enter your participation, and then depending on your input, the second list box will show you a list of universities in the country.

'Change selection of first combobox
Private Sub cbxClient_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbxClient.SelectedIndexChanged
  Try
    If cbxClient.SelectedIndex <> -1 Then
      GetAccount()
    End If
  Catch
    Throw
  End Try
End Sub

'Based on selection of first combobox, update the data sorce of second combobox
Private Sub GetAccount()
  Try
    m_listAccount.Clear()

    Dim strClient As String = cbxClient.SelectedItem.ToString

    For i As Integer = 0 To m_listDS.Count - 1
      If m_listDS(i).Client.Tostring = strClient Then
        m_ds = m_listDS(i)
        Exit For
      End If
    Next

    If Not m_ds Is Nothing Then
      For Each row As DataRow In m_ds.Tables("Account").Rows
        m_listAccount.Add(row("account").ToString)
      Next
    End If

    cbxAccount.DataSource = m_listAccount

  Catch ex As Exception
  End Try
End Sub

My problem is that although m_listAccount updates (there is correct information), the selection shown in cbxAccount is not updated according to m_listAccount (has incorrect information). I do not understand why this is happening.

. , m_listAccount { "old1" } ( 1 ), m_listAccount { "" }. :

cbxAccount.DataSorce={"new"}
cbxAccount.SelectedItem={"old1"}

cbxAccount "old1".

+3
2

,

cbxAccount.DataSource = Nothing
cbxAccount.DataSource = m_listAccount

, , , .

,    m_listAccount.AcceptChanges()

m_listAccount DataTable

+1

, , ..

cbxAccount.DataBind()

.

0
source

All Articles