开发者

Winforms databinding with interface inheritance

I need someone to confirm what I am seeing before I may a change to the domain of the application because of this issue. The issue is that when databinding against interfaces that inherit from one another, you can not see the properties on the base interfaces.

I am working on a WinForms application that uses databinding. This is in .net3.5 and no I can not use wpf.

Anyways, I have a setup something like this.

public interface IClassOne
{
    string Prop1 { get; set; }
}

public interface IClassTwo : IClassOne
{
    string Prop2 { get; set; }
}

public abstract class ClassOne : IClassOne
{
    public string Prop1 { get; set; }
}

public class ClassTwo : ClassOne, IClassTwo
{
    public string Prop2 { get; set; }
}

The base class would hold co开发者_运维问答mmon properties and logic. The base interface would have those common properties on it so they would have to be implemented on each concrete implementation.

If I was databinding to my class structure above, I would be binding to IClassTwo. The problem is when I databind to IClassTwo, I can not see Prop1 in any of the designer operations for WinForms. Even if I get around that limitation and get a control to be bound to Prop1, it does not work.

However if I bind two ClassTwo, then databinding works.

I do not want to deal with the concrete classes because that would make using mocks and testing too hard. I also do not want to put everything on IClassTwo because I would have to repeat code when I make another concrete implementation.

What I need to know is if this truly doesn't work. If you know why, that would be a bonus.

Thank you Tony


http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/4151e6b6-44f7-45e2-9a8e-92c4f8539095/?prof=required

Here is a snippit of what is posted on MSDN as to why this doesn't work. The poster who wrote this goes by "franking".

No, it's not possible to bind to an interface! BindingSource offers some help to use a type as data source. Internally it will instantiate a BindingList<> instance using the type information. Also adding new items will work, but AddNew() will fail unless you subscribe the AddingNew event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜