Tuesday, September 13, 2005

期待以久的Binding.ReadValue

以往在Windows Form中,假如我們在ColumnChanged,ColumnChanging更改某欄
位的值後,Binding Control是不會跟著更新的,而是要等到EndEdit才會更新,在.NET 2.0
中,Binding提供了ReadValue方法,可以強制Binding Control重新取值.
以下的範例展示如何使用ReadValue.

protected virtual void UpdateControlValue(CurrencyManager currencyMangaer)
{
foreach (Binding bind in ((ICurrencyManagerProvider)
_bindingSource).CurrencyManager.Bindings)
bind.ReadValue();
}

public void UpdateControlValue()
{
UpdateControlValue(((ICurrencyManagerProvider)
_bindingSource).CurrencyManager);
}

No comments: