用户控件中的组合框。设置数据绑定
我在用户控件中有一个组合框,我想对其进行数据绑定,但我在 Visual Studio 2008 设计器视图的属性菜单中唯一可以访问的内容是数据源和显示成员。有没有办法设置用户控件,以便我也可以在属性菜单中编辑选定的值成员?
[System.ComponentModel.ComplexBindingProperties("DataSource", "DisplayMember")]
public partial class CustomComboBox : UserControl
{
private object dataSource;
private string displayMember;
[AttributeProvider(typeof(IListSource))]
public object DataSource
{
get
{
return this.dataSource;
}
set
{
this.dataSource = value;
}
}
public String DisplayMember
{
get
{
return this.displayMember;
}
set
{
this.displayMember = value;
}
}
public CustomComboBox()
{
InitializeComponent();
}
private void BindComboBox()
{
if (this.dataSource == null || this.displayMember == null)
{
return;
}
Binding binding = new Binding("DataSource", this.dataSource, this.displayMember, true);
Binding binding2 = new Binding("DisplayMember", this.dataSource, this.displayMember, true);
this.comboBox1.DataBindings.Clear();
this.comboBox1.DataBindings.Add(binding);
this.comboBox1.DataBindings.Add(binding2);
}
}
I have a combobox in a user control and i want to data bind it but the only things i have access to in the properties menu of the visual studio 2008 designer view is the data source and display member. Is there a way to setup the usercontrol so i can edit the selected value member in the properties menu too?
[System.ComponentModel.ComplexBindingProperties("DataSource", "DisplayMember")]
public partial class CustomComboBox : UserControl
{
private object dataSource;
private string displayMember;
[AttributeProvider(typeof(IListSource))]
public object DataSource
{
get
{
return this.dataSource;
}
set
{
this.dataSource = value;
}
}
public String DisplayMember
{
get
{
return this.displayMember;
}
set
{
this.displayMember = value;
}
}
public CustomComboBox()
{
InitializeComponent();
}
private void BindComboBox()
{
if (this.dataSource == null || this.displayMember == null)
{
return;
}
Binding binding = new Binding("DataSource", this.dataSource, this.displayMember, true);
Binding binding2 = new Binding("DisplayMember", this.dataSource, this.displayMember, true);
this.comboBox1.DataBindings.Clear();
this.comboBox1.DataBindings.Add(binding);
this.comboBox1.DataBindings.Add(binding2);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终为我想要编辑的每个字段添加了一个属性,并在所有属性之上添加了 [Browsable(true)]。这让我可以在属性菜单中将所有内容编辑为文本字段。
I ended up adding a property for every field i wanted to edit and added [Browsable(true)] above all the properties. This let me edit everything as a text field in the properties menu.