I have been trying to create a custom datagrid control which will be able to show hierarchical data with a collapsible format. I have a basic implementation by using the datagrid column as such in a webform but what i am trying out right now is to create a server control which will have the ability to bind hierarchies within it.
I have created one custom column by inheriting from TemplateColumn and have my own properties as to specify how many rows do i need to expand or collapse if a image on the column at a particular row is clicked. This data is bindable too. hmm.. well it seemed straight forward initially but i am having too many issues because there are lots of dependencies that have to taken care in the Databound event of the datagrid.
One of the annoying things is that i have got stuck is not knowing how to convert the datasource into a generic holder of data. We know that for some XYZ object to be a bindable source, the object should implement IList and so i can safely cast the datasource to IList and get a handle. But the problem is that the items in the IList, since they are loosely typed, return only objects ! Since precise knowledge on what type of data is stored in the list is not known, i am not able to get the appropriate data eventhough i know the column name i am dealing with pretty well.
If the datasource is say an DataView then i would do it in the datagrid as
System.Collections.IList source = (System.Collections.IList)this.DataSource ;
HierarchyColumn coln = (HierarchyColumn)this.Columns[num] ;
bool data = (bool)((DataRowView)source[num]).Row[coln.DataField] ;
Well but what if the datasource is just a custom class that implements IList ! hmm.. Ain't that a bummer ? Since IList has a collection of objects and not any type specific instances, the cast cannot be done to any specific type and so there cannot be a standard way to retrieve data from the collection.
Well has anyone faced a situation like this in using collections ??
This is really not fair :(