Move & Modify Entities to a New Collection

Posts   
 
    
ToadFace
User
Posts: 4
Joined: 15-Mar-2005
# Posted on: 16-Mar-2005 20:55:48   

This is a question I should know the answer to, so please forgive me for asking....

If I wanted to move data from one collection to a new (empty) collection, would this be the correct method?

myColA .... collection of XYZEntity (contains data) myColB .... collection of XYZEntity (empty)

Move items from "A" to "B".


Dim myLine as XYZEntity

For each myLine in myColA

     if myLine.ProductID > 2000 then
          Dim NewLine As XYZEntity = myColB.AddNew
          NewLine = myline 'copies the data from the existing entity 
          NewLine.IsNew = True
          NewLine.Amount = 0 'make changes to the new entity
          myColB.Add(NewLine) 'add the entity to the new collection
     end if

Next


I'm confused as to what the AddNew does. Could we not just create a new entity and then add it.

Like:


     Dim NewLine as new XYZEntity

     NewLine.ID = 11
     NewLine.Amount = 999
     ....

     myColB.Add(NewLine)


Thanks for your help!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 17-Mar-2005 12:55:57   

AddNew() is the IBindingList.AddNew() method. This method is used by grids when you click on that new empty row at the bottom of the rows in a grid simple_smile

It creates a new instance of the entity which factory is set in the collection and adds it to the collection. So either you can add it yourself or you can use AddNew().

Frans Bouma | Lead developer LLBLGen Pro