我有 2 个数据成员的类供应商是 SupID 和 SupplierName 和 1 个构造函数,然后我在 Form1 load() 时将此对象添加到供应商列表中。
Dim lst As New List(Of Supplier)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddList()
End Sub
Public Sub AddList()
lst.Add(New Supplier("Sup1", "Supplier1"))
lst.Add(New Supplier("Sup2", "Supplier2"))
lst.Add(New Supplier("Sup3", "Supplier3"))
lst.Add(New Supplier("Sup4", "Supplier4"))
lst.Add(New Supplier("Sup5", "Supplier5"))
End Sub
然后我想在单击发送按钮时通过其新的即时构造函数将 lst 发送到 Form2:
Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
Dim frm As New Form2(lst)
frm.Show(Me)
End Sub
接下来在form2中,代码如下:
Dim lst As New List(Of Supplier)
Dim bs As BindingSource
Public Sub New(ByVal lst As New List(Of Supplier)
Me.InitializeComponent()
Me.lst = lst
bs = new BindingSource(lst,nothing)
End Sub
然后我想从 bs 中删除对象:
Public Sub cmdRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemove.Click
bs.RemoveCurrent()
End Sub
问题是,当我从 Form2 中的 bs 中删除对象时,Form1 中 lst 中的对象也会受到影响。那么,如果我不希望 Form1 中的列表受到影响,我该怎么办?
先感谢您....