gpt4 book ai didi

c# - 数据绑定(bind)自定义控件

转载 作者:太空狗 更新时间:2023-10-29 20:38:06 25 4
gpt4 key购买 nike

我有一个自定义控件(Windows 窗体),它是一个查找文本框。控件上的一个属性是当前选择,它是一个包含“标识符”、“代码”和“描述”的自定义对象。此属性是使用 BindingSource 的数据绑定(bind)。

显示信息效果很好。另一方面,无论我将更新设置为 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);
}
}

最佳答案

实现 INotifyPropertyChanged 似乎是解决方案!

    #region IPropertyChanged

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}

protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (null != PropertyChanged)
{
PropertyChanged(this, e);
}
}

#endregion

关于c# - 数据绑定(bind)自定义控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/607170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com