0

我有一个有 9 个 texbox 的表单,当我单击某个按钮时,它会将其中的任何内容添加到列表框中,我还有一个删除按钮,可以从列表框中删除一个项目,有没有办法可以删除该项目并清除它来自的文本框?

4

2 回答 2

0

尝试这个 ..

Public Class Form1
Dim oLB As TextBox
Dim aList As New List(Of TextBox)

Sub GetLB(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus, TextBox3.GotFocus
    oLB = CType(sender, TextBox)
End Sub

Private Sub btnMoveToList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveToList.Click
    ListBox1.Items.Add(oLB.Text)
    aList.Add(oLB)
End Sub

Private Sub btnRemoveItem_Click(ByVal sender As System.Object, ByVal e As   System.EventArgs) Handles btnRemoveItem.Click
    Dim n As Integer = ListBox1.SelectedIndex

    aList(n).Text = ""
    ListBox1.Items.RemoveAt(n)
    aList.RemoveAt(n)
End Sub
End Class
于 2013-04-27T16:38:41.640 回答
0

从 ListBox 中删除项目:

ListBox1.Items.Remove(sItemtext)
ListBox1.Items.RemoveAt(indexItem)

清除文本框:

TextBox1.Text = ""
于 2013-04-27T08:49:12.097 回答