如何填充TextBox,使用逗号分隔的ComboList添加所有选定的值,以便我可以在我的查询中使用

时间:2018-01-19 22:57:12

标签: vbscript

如何从ComboList(字段名称)中选择值到textBox,以便我可以使用VBScript在查询中使用逗号分隔的文本框值?

Combo1.AddItem("Field1")
Combo1.AddItem("Field2")
Combo1.AddItem("Field3")
Combo1.AddItem("Field1")

所以我可以在查询中使用它:

SELECT Field1, Field2, Field4 FROM TableName;

1 个答案:

答案 0 :(得分:0)

这将添加和删除项目。

 Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    Dim selectedField As String = ComboBox1.Items(ComboBox1.SelectedIndex)
    If (selectedField.Length > 0) Then
        If (query.Contains(selectedField)) Then
            query = query.Remove(query.IndexOf(selectedField + ","), (selectedField + ",").Length)
        Else
            query += selectedField + ","
        End If
        TextBox1.Text = query
    End If
End Sub