ejm*_*ack 7 c# controls winforms
我有一个自定义控件(Windows窗体),它是一个查找文本框.Control上的属性是Current Selection,它是包含"Identifier","Code"和"Description"的自定义对象.此属性是使用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);
}
}
Run Code Online (Sandbox Code Playgroud)
实施 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4017 次 |
| 最近记录: |