I have Class Supplier with 2 data member are SupID and SupplierName and 1 Constructor then I add this objects into List of Supplier when 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
And then I want to send lst to Form2 by its new instant constructor when I click Send Button:
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
Next In form2, code like this:
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
And then I want to remove the object from bs:
Public Sub cmdRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemove.Click
bs.RemoveCurrent()
End Sub
The problem is that, when i remove the object from bs in Form2, the object in lst in Form1 is affected too. So how can I do if I don’t want the list in Form1 affect?
Thank you in advance….
Try changing the code in
Form2to this: