我有两个相关的组合框。我的问题是当我从组合框 1 中选择项目时,我的组合框 2 项目不会重置/清除。相反,它会不断在组合框2 的底部添加/附加新项目。我在添加新项目之前尝试过 ComboBox2.DataSource = Nothing
, ComboBox2.Items.Clear()
但仍然不清楚。
Private Sub ComboBox1_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.Validated
ComboBox2.DataSource = Nothing
ComboBox2.Items.Clear()
ComboBox2.Items.Remove(ComboBox2.DisplayMember)
sql = "select brgyname,idbrgy from barangay where idmun=" & ComboBox1.SelectedValue.ToString
da = New Odbc.OdbcDataAdapter(sql, con)
da.Fill(ds, "cbBrgy")
ComboBox2.DataSource = ds.Tables("cbBrgy")
ComboBox2.DisplayMember = "brgyname"
End Sub