1

Microsoft.VisualBasic.PowerPacks.DataRepeater.Net 4.0 (c#) winforms プロジェクトでVisual Basic Power Packs ( ) のデータ リピーターを使用しています。私はそれDataSourceをジェネリックにバインドしています(プロパティを設定しています)List<T>。T は私のビジネス クラスの 1 つにすぎません。

データ リピーターに配置したコントロールは UserControl です。UserControl には、 と呼ばれる T 型のパブリック プロパティがありMyItemます。

コレクション内の T 型の実際の項目に UserControlのプロパティをバインドしたいのですMyItemが、うまくいきません。タイプ T のプロパティの 1 つにバインドできますが、コレクション アイテム自体にはバインドできません。コレクション全体にバインドしようとしているのではなく、データ リピーター (現在のアイテム) のその行に対応するコレクションのメンバーにバインドしようとしていることに注意してください。

これを機能させるには、メソッドのdataMemberパラメーターに何を入力すればよいですか? DataBindings.Add私は試してみました"."が、役に立ちませんでした。"/"""

ここに私のコレクションオブジェクトがあります:

public class MyClass
{
  public string SomeProperty {get; set;}

    public MyClass Self
    {
        get
        {
            return this;
        }
        set
        { 

        }
    }

}

ここに私のユーザーコントロールがあります:

public partial class MyUserControl : UserControl
{


    public MyUserControl()
    {
        InitializeComponent();
    }

    private MyClass _myItem;
    public MyClass MyItem
    {
        get 
        {
            // this never gets called
            return _myItem;
        }
        set {
            // this never gets called
            _myItem = value;
            // Do something with _myItem
        }
    }

    private string _APropertyToBindToOneOfMyItemsProperties;
    public string APropertyToBindToOneOfMyItemsProperties
    {
        get
        {
            // this gets called
            return _APropertyToBindToOneOfMyItemsProperties;
        }
        set
        {
            // this gets called
            _APropertyToBindToOneOfMyItemsProperties = value;
        }
    }
}

そして、これはデータリピーターを含むコントロール内の私のコードで、データリピーターにデータをロードする責任があります:

    var MyCollection = new List<MyClass>();
    MyCollection.Add(new MyClass() {SomeProperty = "Value1"});
    MyCollection.Add(new MyClass() {SomeProperty = "Value2"});
    this.MyUserControl1.DataBindings.Add("APropertyToBindToOneOfMyItemsProperties", MyCollection, "SomeProperty"); // this works!
    this.MyUserControl1.DataBindings.Add("MyItem", MyCollection, "/"); // can't get this to work!
    this.MyUserControl1.DataBindings.Add("MyItem", MyCollection, "Self"); // can't get this to work either!

    this.MyDataRepeater.DataSource = MyCollection;
4

0 に答える 0