【发布时间】:2010-10-11 01:36:15
【问题描述】:
我有一个自定义控件(Windows 窗体),它是一个查找文本框。控件上的一个属性是当前选择,它是一个包含“标识符”、“代码”和“描述”的自定义对象。此属性是使用 BindingSource 的 Databound。
显示信息效果很好。另一方面,无论我将 Update 设置为 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);
}
}
【问题讨论】:
-
您能告诉我们您创建数据绑定的代码吗?
-
谢谢,您的问题很有帮助。出于某种原因,MSDN 教程在其教程中省略了 [Bindable(true)] 属性。这是一个重要的细节!