1

Microsoft.VisualBasic.PowerPacks.DataRepeater在 .Net 4.0 (c#) winforms 项目中使用 Visual Basic Power Packs ( ) 中的数据中继器。我将它(设置DataSource属性)绑定到通用List<T>. T 只是我的商务舱之一。

我在数据转发器中放置的控件是 UserControl。UserControl 有一个名为 T 的公共属性MyItem

我想将MyItemUserControl 的属性绑定到集合中 T 类型的实际项目,但它不起作用。我可以绑定到 T 类型的属性之一,但不能绑定到集合项本身。请注意,我不是试图将它绑定到整个集合,而是与数据重复器(当前项)中的该行一起使用的集合成员。

我可以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