0
我有一個表單,有9個texbox,當我點擊某個按鈕時,它將任何內容添加到列表框,我也有一個刪除按鈕,從列表框中刪除一個項目,有沒有辦法我可以刪除該項目並清除它來自的文本框?從Control從列表框中刪除項目
我有一個表單,有9個texbox,當我點擊某個按鈕時,它將任何內容添加到列表框,我也有一個刪除按鈕,從列表框中刪除一個項目,有沒有辦法我可以刪除該項目並清除它來自的文本框?從Control從列表框中刪除項目
刪除項目:
ListBox1.Items.Remove(sItemtext)
ListBox1.Items.RemoveAt(indexItem)
清除文本框:
TextBox1.Text = ""
試試這個..
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
WPF \的WinForms? – Guy 2013-04-27 09:03:25