如何在vb.net

时间:2017-04-02 16:42:49

标签: vb.net checkbox listbox

我希望能够同时将复选框中的许多选定项目添加到列表框中。这是代码的示例

If CheckBox1.Checked Then
choice = "Potato soup"
quantity = Val(txtapp1.Text)
price = "80"
If CheckBox2.Checked Then
choice = "Mini tacos"
quantity = Val(txtapp2.Text)
price = "95"

我希望能够同时为列表框添加每个复选框的选项,数量和价格。

1 个答案:

答案 0 :(得分:0)

假设您的列表框名为ListBoxChoices,代码将如下:

If CheckBox1.Checked Then
choice = "Potato soup"
quantity = Val(txtapp1.Text)
price = "80"
ListBoxChoices.Items.Add(choice)
ListBoxChoices.Items.Add(quantity)
ListBoxChoices.Items.Add(price)
End If
If CheckBox2.Checked Then
choice = "Mini tacos"
quantity = Val(txtapp2.Text)
price = "95"
ListBoxChoices.Items.Add(choice)
ListBoxChoices.Items.Add(quantity)
ListBoxChoices.Items.Add(price)
End If