Creating Properties at Run-Time (BindingLists)

link664

Member
Joined
Nov 13, 2007
Messages
6
Programming Experience
5-10
Hi guys,

I have a bit of a dilemma that I'm hoping you can help with. I am currently developing a program that involves binding IBindingLists to an Infragistics control called UltraWinGrid. Not sure if many of you have heard of it but if not it doesn't really matter.

The program involves creating objects of type MyClass, placing them in a bindinglist of type MyClass, and then binding this to the grid's datasource. Additionally, each object has its own bindinglist property, which will be set in the same way, therefore creating a hierarchical grid.

For example, say I had three classes: clsA, clsB and clsC. A grid might eventually look like this:
a1
|- b1
| |- c1
|
|-b2

where 'a1' has children 'b1' and 'b2', and 'b1' has a child 'c1'.

Now to create this is no big deal, simply assign all clsA objects a bindinglist(of clsB) and all clsB objects a bindinglist(of clsC). HOWEVER (drum roll!) it may not always follow a certain order so I can have a grid that could look like this:
a1
|- c1
|
|- c2
|-b1

where 'a1' has children 'c1' and 'c2', and 'c2' has a child 'b1'.

So in this case, I would assign all clsA objects a bindinglist(of clsC) and all clsB objects a bindinglist(of clsB). This is also fine, I have created a recursive function that will do this.

Now is where my problem arises. The bands in the grid might not always have the same TYPE of object in them. A grid could also look like this:
a1
|-b1
| |-c1
|
|-c2

where 'a1' has children 'b1' and 'c2', and 'b1' has a child 'c1'. This is impossible to do at the moment as I only have one bindinglist property and you can't have different types in a typed bindinglist. So I have to have more than one bindinglist, one for each type. But to make matters worse, I can theoretically have n number of types to add to a single level, therefore needing an n number of bindinglists. Additionally I can't just have an array or a collection of bindinglists as the original property and add to that, as the Infragistics binding method will bind to the objects in the array/collection, i.e. the bindinglist objects themselves, and not the objects inside these bindinglists.

So to cut a long story short, I need some way of creating extra bindinglist properties at run-time for an instance of a class. I have found quite a bit on using Reflection.Emit PropertyBuilder method but that only seems to apply to types, rather than instances. Also, I'm a bit confused as to how I would apply this to an already existing class/type.

Sorry if this has been a bit long-winded but I thought I better explain exactly what I was doing. Any help, guidance or ideas would be greatly appreciated.

Thanks,
Link664
 
Can't you have a Bindinglist(Of Object) and put different type objects in it? Would think the control reflects the binded objects, and not type of bindinglist. Maybe you also have to use a common type (base or interface), I don't know the UltraWinGrid.
 
The way the UltraWinGrid works when binding to an object is that it looks for all the public properties of that object and displays them in the grid. Unfortunately this means if i were to declare a bindinglist(of object) or even a bindinglist(of MySuperClass) and make all other classes inherit MySuperClass, it will only bind to the public properties of the type specified in the binding list, and not the properties specified in the actual object type. Freakin annoying and a limitation set by using the UltraWinGrid but unfortunately its not my decision whether to use it or not.
 
But the instance boxed in the Object list is still the same type it was, it is not Object type. The standard DataGridView control handles this fine as long as all items in the list are same type. What if you were to try it?
 
Back
Top