I work for an Architecture firm and I am creating a plug-in for a 3D modeling program to assist design. I have a Building class, and a Floor class. The building contains a reference to a FloorList collection of floors. I'm trying to figure out what to base the FloorList collection off of so that I can minimize the amount of work I need to do to create an interface to edit the collection.
The Floor collection represents a series of building floors that are stacked on top of one another. Each Floor has a Floor.Height property that is read write, and an Floor.Elevation property that is read only and set by totaling the floor heights below the current Floor. So, whenever a Floor is added, removed, moved, or changed in the collection the Floor.Elevation properties need to be updated.
In addition, I want to create a UI to edit this collection. I was thinking of using a DataGrid control where each Floor is listed with its Height and other properties as a row of the control. The user should be able to add, remove, and re order floors using the control. I'd like setting this up to be as easy and flexible as possible. Meaning I'd like to simply be able to bind the collection of Floors to the DataGrid and have the columns of the DataGrid populate based on the properties of the Floor class. If possible I'd like to be able to utilize the built in Add/Remove UI interface of the DataGrid control with out having to mess with setting up a bunch of event relationships between my collection and the DataGrid.
To complicate things further in the future I'll need to be able to allow the user to dynamically add custom properties to the Floors that I'll want them to be able to see and edit in the DataGrid as well. I think I'd end up doing that by having Floor class implement IExtenderProvider. So ultimately the DataGrid would look something like this:
Initial Properties Future Custom User Properties Height Elevation ProgramType UnitType UnitCount 15' 70' Residential Luxury 5 15' 55' Residential Luxury 5 15' 40' Residential Budget 10 20' 20' Retail N/A 2 20' 0' Retail N/A 3
My question now is what should I base my FloorList collection off of to allow for this functionality? The options I'm considering are as follows.
1) Inherit from List(Floor)
- Methods such as Add/Remove are not vitrual and thus I can't not override them to update the elevations
2) Implement IList(Floor)
OnChange event is not built in so if the lists changes the DataGrid will not update (I think?)
I think this is probably the best option but what would I need to do the ensure that changes to the FloorList collection or DataGrid are synced with one another?
3) Inherit from BindingList(Floor)
- Method like Add/Remove are not virtual so I can't modify them to update the floor elevations.
4) Implement IBindingList
- IBindinglist is not generic and I only want my collection to contain Floor objects