如何同时使用相同的查询填充几个组合框

时间:2017-07-30 22:23:42

标签: vb.net

如何一次使用相同的查询填充几个组合框

Dim sqlmatriz1 As String = "select equipo from teams order by equipo "
Dim trasn1 As New SqlDataAdapter(sqlmatriz1, sconexionca)
Dim dtrans1 As New DataSet
trasn1.Fill(dtrans1, "teams")

With ComboBox1
    .DataSource = dtrans1.Tables.Item("teams")
    .DisplayMember = "equipo"
    .ValueMember = "equipo"
    '  .Text = ""
End With

我同时对表单中的所有ComboBox es都需要相同的内容 问候

2 个答案:

答案 0 :(得分:0)

 For i = 1 To 4
        Dim cbx As ComboBox = Me.Controls("Combobox" & (i))
        With cbx
            .DataSource = dtrans1.Tables.Item("teams")
            .DisplayMember = "equipo"
            .ValueMember = "equipo"
            '.Text = ""
        End With
    Next

答案 1 :(得分:0)

您可以创建一个带有ComboBox名称的“Sub”。

self.dismiss(animated: true, completion: {});
self.navigationController?.popViewController(animated: true);

并称之为。

Sub populateComboBox(Byval ComboBoxName as ComboBox)
//your code
with ComboBoxName
//your code
End with
End Sub