列表框没有完全删除项目
Listbox is not completely removing items
我有一个表单,可以将选中的列表框中的选定项目存储到另一个表单的列表框中。
'Form2
Public Sub New(ByVal Citems As List(Of String), ByVal Citems2 As List(Of String))
InitializeComponent()
ListBox1.Items.AddRange(Citems.ToArray)
ListBox2.Items.AddRange(Citems2.ToArray)
Private Sub Cancel_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Cancel the form and returns to Form 1
ListBox1.Items.Clear()
ListBox1.Refresh()
ListBox2.Items.Clear()
ListBox2.Refresh()
Me.Close()
End Sub
'Form 1
Dim Citems As New List(Of String)
Dim Citems2 As New List(Of String)
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
For Each I As String In CheckedListBox1.CheckedItems
Citems.Add(I)
Next
For Each I As String In CheckedListBox2.CheckedItems
Citems2.Add(I)
Next
Dim SecondForm As New Form2(Citems, Citems2)
SecondForm.Show()
这是我拥有的用于清除列表框并关闭表单的代码。问题是当它再次打开时,先前选择的项目仍在列表框中。如何在不完全关闭应用程序的情况下清除数据?
这个有效:
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Citems.Clear()
For Each I As String In CheckedListBox1.CheckedItems
Citems.Add(I)
Next
Citems2.Clear()
For Each I As String In CheckedListBox2.CheckedItems
Citems2.Add(I)
Next
在添加之前清除列表。感谢您的帮助。
我有一个表单,可以将选中的列表框中的选定项目存储到另一个表单的列表框中。
'Form2
Public Sub New(ByVal Citems As List(Of String), ByVal Citems2 As List(Of String))
InitializeComponent()
ListBox1.Items.AddRange(Citems.ToArray)
ListBox2.Items.AddRange(Citems2.ToArray)
Private Sub Cancel_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Cancel the form and returns to Form 1
ListBox1.Items.Clear()
ListBox1.Refresh()
ListBox2.Items.Clear()
ListBox2.Refresh()
Me.Close()
End Sub
'Form 1
Dim Citems As New List(Of String)
Dim Citems2 As New List(Of String)
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
For Each I As String In CheckedListBox1.CheckedItems
Citems.Add(I)
Next
For Each I As String In CheckedListBox2.CheckedItems
Citems2.Add(I)
Next
Dim SecondForm As New Form2(Citems, Citems2)
SecondForm.Show()
这是我拥有的用于清除列表框并关闭表单的代码。问题是当它再次打开时,先前选择的项目仍在列表框中。如何在不完全关闭应用程序的情况下清除数据?
这个有效:
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Citems.Clear()
For Each I As String In CheckedListBox1.CheckedItems
Citems.Add(I)
Next
Citems2.Clear()
For Each I As String In CheckedListBox2.CheckedItems
Citems2.Add(I)
Next
在添加之前清除列表。感谢您的帮助。