1

I am using a data repeater from Visual Basic Power Packs (Microsoft.VisualBasic.PowerPacks.DataRepeater) in .Net 4.0 (c#) winforms project. I am binding it (setting the DataSource property) to a generic List<T>. T is just one of my business classes.

The control I have placed in the data repeater is a UserControl. The UserControl has a public property of type T called MyItem.

I want to bind the MyItem property of the UserControl to the actual item of type T in the collection, but it does not work. I can bind to one of the properties of type T, but not the collection item itself. Note, I'm not trying to bind it to the whole collection, but rather the member of the collection that goes with that row in the data repeater (the current item).

What can I type into the dataMember parameter of the DataBindings.Add method to make this work? I have tried ".", "/" and "" with no avail.

Here's my collection object:

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

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

        }
    }

}

Here is my user control:

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;
        }
    }
}

And here is my code in the control that contains the data repeater, which is responsible to load the data repeater with data:

    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;
toddmo
  • 20,682
  • 14
  • 97
  • 107
  • What is `lookupDocuments`, I thought `MyCollection` should also be the `DataSource` of your `MyDataRepeater`? – King King Jul 25 '13 at 01:51
  • using `DataBindings`, the third parameter should always be a `Property`, if there is not any desired property, you have to define the property in your class (whose an instance is passed as the second parameter) first. – King King Jul 25 '13 at 01:56
  • @King King, that has been changed to MyCollection. Sorry. – toddmo Jul 25 '13 at 15:23
  • @KingKing, I could not get your work-around to work. I have edited my question to encompass that. – toddmo Jul 25 '13 at 15:35

0 Answers0