0
我在用戶控件中有一個組合框,並且我想要將其綁定到數據,但唯一可以在Visual Studio 2008設計器視圖的屬性菜單中訪問的是數據源和顯示成員。有沒有辦法設置usercontrol,所以我可以在屬性菜單中編輯選定的值成員呢?。設置數據綁定
[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);
}
}