字符串看起來像11,33,44 我做了三個字符串拆分成3個文本框,然後當我做ListBox1.Items.Remove(ListBox1.SelectedItem)它不起作用。如何刪除列表框中的項目在vb
它說ss.Split(「,」)對象引用未設置爲對象的實例。
這裏是我的代碼
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim ss As String = ListBox1.SelectedItem
Dim aryTextFile(2) As String
aryTextFile = ss.Split(",")
TextBox1.Text = (aryTextFile(0))
TextBox2.Text = (aryTextFile(1))
TextBox3.Text = (aryTextFile(2))
ss = String.Join(",", aryTextFile)
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text + "," + TextBox2.Text + "," + TextBox3.Text)
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub
但如果我刪除列表框中的整個部分,可以刪除列表框中的項目。只有當我使用拆分或其他方法來分隔字符串,它會得到錯誤 –