【发布时间】:2012-11-28 13:10:40
【问题描述】:
我通过以下方式进行DataBinding
private List<MyEditor> Editors { get; set; }
private Dictionary<int,object> dictionary
private void SetEditors()
{
Editors.Clear();
foreach (var element in dictionary)
{
var editor = MyFactory.GetEditor();
editor.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
editor.DataBindings.Add("Value", element, "Value");
//some code
Editors.Add(editor);
}
//some more code
}
然后在 GUI 中我对 Editors[0] 的 Value 进行了一些更改,之后在另一段代码中我尝试从 dictionary 元素中获取值并发现它没有改变,即使我使用Editors[0].DataBindings["Value"].WriteValue() 确保数据写入dictionary。
在调试器中我可以看到下图:
Editors[0].DataBindings["Value"] {System.Windows.Forms.Binding} System.Windows.Forms.Binding
....
DataSource {[0, oldValue]} object {System.Collections.Generic.KeyValuePair<int,object>}
....
同时
Editors[0].Value "newValue" object {string}
可能是什么?将不胜感激任何想法。
【问题讨论】:
标签: c# .net winforms data-binding