根据组合框中的所选项目更改数据

Change data according to selected item in combobox

我调用了一个函数,该函数对 SQLServer 和 returns 一个包含多列的 DataTable 运行查询。我希望 DataTable 中的数据根据​​组合框中的所选项目更改行。

Dim dt As New DataTable
Dim rInt As New Int32

dt = subGetDB()
rInt = ComboBox1.SelectedIndex
Textbox1.Text = dt.Rows(rInt)("description").ToString()
TextBox2.Text = dt.Rows(rInt)("accountFilter").ToString()

到目前为止,我的做法是否正确?

是的...但是您需要将上面的所有代码放入 ComboBox1 对象的 SelectedValueChanged 事件中。