Assign / Unassign between two lists

Assign / Unassign between two lists

Old forum URL: forums.lhotka.net/forums/t/6106.aspx


eulerthegrape posted on Thursday, January 08, 2009

I have one list that is a collection of pieces of equipment assigned to a part used during a measurement.  At first I thought it would make sense to make this list a child of part but really that is not the correct behavior as it's not a list that would persist with part but rather a list that is recalled during a measurement.  I suppose it could be a child of a measurement BO, if one existed.

So, I am left to conclude that this partEquipmentList is an Editable Root List.?  I want to be able to add items from a master equipment list and remove them from the partEquipmentList.  Items in one list should not appear in the other as we cannot have duplicate pieces of equipment assigned to a part.  The partEquipmentList should not be saved until the user chooses to do so.  The table for partEquipmentList only contains partId, equipment Id, and LastChanged.

Currently I have two datagridview controls one populated with partEquipmentList one populated with the equipmentList; an Assign and an Unassign button; and Save and Cancel buttons.  Any suggestions on how to proceed or example code?

I think I may have just confused myself because this initially seemed trivial and a really common UI scheme. 

Thanks in advance,
euler

triplea replied on Friday, January 09, 2009

What I have done in the past is this:

Parent (BusinessBase - ROOT)
|--->SelectedChildList (EditableChildList - persisted in the db)
|              |-------->SelectedChildItem (EditableChild)
|--->UnselectedChildList (EditableChildList - NOT persisted in the db)
              |-------->SelectedChildItem (EditableChild)

I also have a read only list (lets call it ParentItems). When I create or Fetch a Parent object, I fetch the data for Parent and then for SelectedChildList. Then I create a new instance for UnselectedChildlist like this:

UnselectedChildlist = UnselectedChildlist.NewUnselectedChildlist(_selectedChildList);

Within UnselectedChildlist.Create I get my read-only list ParentItems (which is cached if you want it to) and loop through them. If the parameter (SelectedChildList selectedChildList) contains (check with IDs or whatever works) the looped ParentItem then skip, otherwise add to UnselectedChildlist.

You should end up with data populated in SelectedChildList from the DB and also populate your non-persisted UnselectedChildlist to contain all items that have not yet been selected. Then on your UI you have 3 bindingsources, 1 for parent and 1 for each of the selected/unselected lists and bind these to your 2 datagrids.

There are probably better ways of doing this but this is simple and has worked fine for me.

Copyright (c) Marimer LLC