Hello,
I'm binding my grid to a BindingSource. BindingSource.DataSource points to an interface "IMyInterface2", which extends another interface "IMyInterface".
At design time I only see the columns corresponding to properties of IMyInterface2. The properties of IMyInterface are not there. I think it should show every property from IMyInterface and IMyInterface2.
Furthermore, at runtime all the properties from IMyInterface and IMyInterface2 are there. That's very weird.
Have you seen this behavior?
Thanks.
Just to make myself clear, the implementation would look like this:
public interface IMyInterface
{ string PropertyA {get; set;}}
public interface IMyInterface2 : IMyInterface
{ string PropertyB{get; set;}}
Then I set the BindingSource.DataSource to IMyInterface2.
At design time I only see PropertyB. At run time both PropertyA and PropertyB are bounded to the grid.
Hi Oscar,
This is nothing to do with the grid. The BindingManager in DotNet will only expose the properties of the derived interface. You will get the same results binding to any control.
Thanks for the answer Mike. Yes, it's a .NET problem. Looking on the web I found two (not-so-good) workarounds:
1) Declare all the fields fo the base interface as new fields on the extended interface. In my example it would look like this:
{ string PropertyB{get; set;}
new string PropertyA{get; set;}
}
2) Bind the BindingSource to the object implementing the interface instead of the interface.
In my experience, the BindingManager doesn't deal with interfaces very well. It seems to assume that the items your are binding to are concrete implementations. So I would go with option 2, myself. :)