Object Design Question

Object Design Question

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


tna55 posted on Monday, September 21, 2009

I need suggestion/hep with a design problem I am facing.

I have a use-case in which user needs to enter data in a grid however the columns of the grid can vary depending on the template user selects.

This is part of a data import tool basically where the user would select the data they wish to import, the template will create a grid and then data is stored in only those fields in database.

Usually the editable object will have properties bound to grid columns however the columns of the grid are variable I am not sure how to implement this.

Any help will be very appreciated.

Thank you

SonOfPirate replied on Monday, September 21, 2009

I've done the same thing in the past by using a custom TypeDescriptor that knows how to provide the schema (list of columns) to the grid.  Your descriptor could use the underlying template to return the list of properties supported by the template which will be rendered as columns in the grid.  The descriptor would then be used to obtain the value for each property/column from the data.  The TypeDescriptor actually abstracts the implementation you choose for your class but from the grid's perspective, it will see an object with a flat set of properties to which it can bind.

Hope that helps.

 

rsbaker0 replied on Monday, September 21, 2009

The answer to this varies considerably depending on whether the properties of the underlying object are "variable".

If so, then you'll probably need to implement ICustomTypeDescriptor (which is what I believe SonOfPirate was suggesting). I haven't tried it, but I it's possible that implementing the ITypedList interface is another way of accomplishing this.

However, it might also be the case where you are just dynamically configuring which subset of a static set of underlying properties are displayed in the grid, which is an entirely different problem.

Implementing ICustomTypeDescriptor in your primary BO class has some side effects (unfortunately), such as the inability of some parts of the Visual Studio designer to see any of the properties your object implements.

Copyright (c) Marimer LLC