C# Win Forms:如何将DataRepeater中UserControl的属性绑定到集合项本身
我正在使用.NET4.0(c#)winforms项目中Visual Basic Power Pack(C# Win Forms:如何将DataRepeater中UserControl的属性绑定到集合项本身,c#,winforms,data-binding,datarepeater,C#,Winforms,Data Binding,Datarepeater,我正在使用.NET4.0(c#)winforms项目中Visual Basic Power Pack(Microsoft.VisualBasic.PowerPacks.DataRepeater)中的数据转发器。 我正在将它绑定(设置数据源属性)到一个通用的列表。这只是我的一门商务课 我在数据中继器中放置的控件是UserControl。 UserControl有一个名为MyItem的T类型公共属性 我想将UserControl的MyItem属性绑定到集合中类型为T的实际项,但它不起作用。我可以绑定
Microsoft.VisualBasic.PowerPacks.DataRepeater
)中的数据转发器。
我正在将它绑定(设置数据源
属性)到一个通用的列表
。这只是我的一门商务课
我在数据中继器中放置的控件是UserControl。
UserControl有一个名为MyItem
的T类型公共属性
我想将UserControl的MyItem
属性绑定到集合中类型为T的实际项,但它不起作用。我可以绑定到T类型的属性之一,但不能绑定到集合项本身。注意,我并没有试图将其绑定到整个集合,而是绑定到数据中继器中与该行一起的集合成员(当前项)
我可以在数据绑定的dataMember
参数中键入什么内容。添加方法以使此工作正常?
我尝试了“
”、“/”
和”
,但没有成功
这是我的收藏对象:
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;
var MyCollection=newlist();
添加(新的MyClass(){SomeProperty=“Value1”});
添加(新的MyClass(){SomeProperty=“Value2”});
this.MyUserControl1.DataBindings.Add(“APropertyToBindToOneOfMyItemsProperties”,MyCollection,“SomeProperty”);//这管用!
this.MyUserControl1.DataBindings.Add(“MyItem”,MyCollection,“/”);//不能让它工作!
this.MyUserControl1.DataBindings.Add(“MyItem”,MyCollection,“Self”);//这也不能用!
this.MyDataRepeater.DataSource=MyCollection;
什么是查找文档
,我认为MyCollection
也应该是MyDataRepeater的数据源
?使用数据绑定
,第三个参数应该始终是属性
,如果没有任何需要的属性,则必须在类中定义属性(其一个实例作为第二个参数传递)第一个。@King King,已更改为MyCollection。抱歉。@King King,我无法使您的工作正常进行。我已编辑了我的问题以包含该问题。