【发布时间】:2011-01-03 21:43:46
【问题描述】:
我在Databound Windows Forms control does not recognize change until losing focus看到了答案。
但这并不能完全回答我的问题。我有完全相同的情况。在 ToolStrip_click 上,我浏览了所有控件并强制执行“WriteValue()”,但它仍会恢复为保存之前的先前值。谁能建议我如何解决这个问题?我是不是错误地实现了这个?
(查看当前(非工作)解决方案的代码。)
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
// Make sure that all items have updated databindings.
foreach (Control C in this.Controls)
{
foreach (Binding b in C.DataBindings)
{
// Help: this doesn't seem to be working.
b.WriteValue();
}
}
}
代码现在要简单得多,但它是一个相当大的 hack。我很高兴知道是否有更“适当”的解决方法。
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
// Make sure that all text fields have updated by forcing everything
// to lose focus except this lonely little label.
label44.Focus();
}
【问题讨论】:
标签: c# winforms data-binding