1

次の構造を持つオブジェクトのコレクションがあります。

public class Parent
{
    public string Title { get; set; }
    public string Guid { get; set; }
}

public class Child:Parent
{
    public string Description { get; set; }
}

List<Parent> collection ;
collection  = new List<Parent>();

collection.Add(new Parent());
collection.Add(new Parent());
collection.Add(new Child());
collection.Add(new Child());
collection.Add(new Parent());

したがって、一部の要素は親タイプからのものであり、一部は子タイプからのものです(コレクション内のオブジェクト間に継承関係があります)。

次のバインディングを使用しました。

txtTitle.DataBindings.Add("Text", _BindingSource, "Title");
txtGuid.DataBindings.Add("Text", _BindingSource, "Guid");
txtDescription.DataBindings.Add("Text", _BindingSource,"Description");

最初の2つのバインディングは明らかに正常に機能します。しかし、データを正しく表示するには、3番目のものをどうすればよいですか?

4

1 に答える 1

1

彼の著書「Windowsフォーム2.0を使用したデータバインディング」のp。125、著者のBrian Noyesは、BindingSourceのアイテムは同種である必要がある、つまり同じタイプである必要があると述べています。

少なくともBindingSourceコンポーネントでは、あなたがやろうとしていることは不可能に思えます。

于 2012-10-17T03:36:05.207 に答える