If I am binding a grid to a binding list of a given interface using an ultradatasource, and the interface inherits from another interface, is there a way to bind to the parent properties?
I went with option 3, and it was terribly easy. I grabbed an example from http://msdn.microsoft.com/en-us/library/system.componentmodel.itypedlist.aspx and extended binding list.
I changed the constructor from this link to accept a list of interface names and reworked the guts to combine all applicable properties.
// Get the 'shape' of the list.
// Only get the public properties marked with Browsable = true.
var propertyList = new List<PropertyDescriptor>(objectProperties.Count);
propertyList.Add(descriptor);
interfaces.ForEach(x => {
if (interfaceType != null){
}
});
// PropertyDescriptorCollection does not support add or insert. Only the constructor allows you to control the list
I then inherit from this and bind the grid to AuditBindingList, which produces all of my columns. Of course, I can now use custom attributes on the interface properties and really control what is available for the grid.
public class AuditBindingList<T> : SortableBindingList<T>{
public AuditBindingList() : base(new List<string> { "IAuditObject" }) { }
Thanks for the suggestion.
The ultradatasource is where I set the columns and keys which are matched to the binding source.
The problem that I encounter is binding to a bindinglist<Interface>. If I bind directly to the editable object, it works fine. It fails when I bind to an interface that inherits from another interface. The inherited interface members are not seen as columns.
If I move the properties of the parent interface into the interface representing the object's shape, it works fine without changing the editable object. It is only the inheritance of the interface that seems to fail.
Hi,
You lost me a little there when you mentioned UltraDataSource. If you are binding to a List, where does UltraDataSource come into it?
Anyway, the grid will display the properties that the DotNet BindingManager tells it to. There's really very little control over this in the grid itself.
I think if you bind the grid to BindingList<x>, then this list implements ITypedList and returns only the properties of x.
There are several ways you can get what you want here, though.