字符串看起来像11,33,44 我将三个字符串拆分为3个文本框,然后当我执行ListBox1.Items.Remove(ListBox1.SelectedItem)时,它不起作用。
它表示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
答案 0 :(得分:1)
当您按ListBox
时从Button2
删除某个项目时,正在调用SelectedIndexChanged
的{{1}}。在那里,所选项目将一无所获,因此要解决此问题,请在分配字符串变量之前在ListBox1
内添加以下行。
SelectedIndexChanged event
答案 1 :(得分:0)
试试这个:
listbox.selecteditem.remove()
它将删除listbox
中的所选项目。