使用.Items和.Add无法识别

时间:2014-11-21 21:07:18

标签: vb.net

我的代码需要帮助:

Private Sub AddButton_Click(ByVal sender As System.Object, 
         ByVal e As System.EventArgs) Handles AddButton.Click
    If Ingredients.Text <> "" And QuantityBox.Text <> "" And UnitBox.Text <> "" Then
        Ingredients.Items.Add(ListBox1.Text)
    End If
End Sub

在我的第三行,有一个问题。当我尝试调试它告诉我&#34; Items不是System.Windows.Form.Textbox的成员。添加也会发生这种情况。我的代码是否有问题,因为我在学校完成了这个代码,而且这个问题不会发生在那里。

1 个答案:

答案 0 :(得分:1)

查看您的代码(以及大量假设),我认为您已将列表框和文本框混合在一起。试试这个?

Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButton.Click
    If Ingredients.Text <> "" And QuantityBox.Text <> "" And UnitBox.Text <> "" Then
        ListBox1.Items.Add(Ingredients.Text)
    End If
End Sub