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;