我有一個自定義控件(Windows窗體),它是一個查找文本框。控件上的一個屬性是當前選擇,它是一個包含「標識符」,「代碼」和「描述」的自定義對象。該屬性是使用BindingSource的Databound。數據綁定自定義控件
顯示信息的效果很好。另一方面,無論我將更新設置爲OnValidate還是OnValueChange,它都不會更新BindingSource。有什麼我想念得到這個自動更新?
private System.Windows.Forms.BindingSource buildPlanComponentDataBindingSource;
public void LoadBuildPlan(string itemNumber)
{
var buildPlanComponents = BuildPlan.LoadBuildPlanComponents(itemNumber, AutomaticPrice);
buildPlanComponentDataBindingSource.DataSource = buildPlanComponents;
AssemblyNumber = itemNumber;
}
[Bindable(true)]
[DefaultValue(null)]
public ILookupSelection CurrentSelection
{
get
{
if (currentSelection == null)
currentSelection = new LookupSelection {Code = txtLookup.Text};
return currentSelection;
}
set
{
if (value == null) return;
currentSelection = value;
SetText(currentSelection, DisplayText);
SetDescription(currentSelection, DisplayDescription);
}
}
你能告訴我們你創建數據綁定的代碼嗎? – overslacked 2009-03-03 16:44:24
謝謝,你的問題是非常有幫助的。出於某種原因,MSDN教程忽略了其教程中的[Bindable(true)]屬性。這是一個重要的細節! – 2016-05-13 15:21:24