View previous topic :: View next topic |
Author |
Message |
RGabo
Joined: 21 Sep 2005 Posts: 11
|
Posted: Thu Jul 06, 2006 11:04 am Post subject: Binding to ancestor of actual class instance |
|
|
Hey,
I have an object model where I have an abstract class Foo and different implementations of that abstract class come from different sources.
I would like to be able to bind to the Foo abstract class and its (abstract) properties. It seems to me that all that happens when I have a binding to Foo and not the actual Foo-derived class is that virtual tree puts foo.ToString() in the first column but doesn't even try to make use of the column-object bindings.
What I have to do now is to not do any binding but use events like GetRowData and GetCellData. It would be nice if the common stuff in my abstract Foo clas could be bound, whenever Foo-derived objects show up in the data source.
Thanks,
Gabor |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Jul 06, 2006 10:37 pm Post subject: |
|
|
You can bind to abstract classes and interfaces – it’s just that the behaviour of System.Type.GetType(name) can be a bit erratic. Virtual Tree resolves the name you set in the binding to a type using Type.GetType() and then checks whether this type is assignable from the object being bound. If GetType returns null (as it does for some reason sometimes with abstract classes) then Virtual Tree will bind based on whether the type name you specified matches the concrete typename of the object being bound (this won't work for abstract classes).
The good news is that its easy to fix this by specifying the TypeName more completely by including the assembly name (eg “MyNamespace.MyType, MyAssemblyName”). Then GetType() will work. An alternative is to set the binding.Type property directly (programmatically) after the InitializeComponent call. _________________ Infralution Support |
|
Back to top |
|
|
|