Cod*_*eld 1 .net data-binding devexpress exception winforms
我们在winforms应用程序中使用了大量的数据绑定,最近我们遇到了一些难以调试的场景.
在我们的BindingSource上调用ResumeBinding()时,我们收到一个异常:
ex.Type FormatException ex.Message无法将值格式化为所需类型:
在System.Windows.Forms.Binding.FormatObject(对象的值)在System.Windows.Forms.Binding.PullData(布尔重新格式化,布尔力)在System.Windows.Forms.BindingManagerBase.PullData(布尔&成功)在System.Windows. Forms.CurrencyManager.CurrencyManager_PullData()在System.Windows.Forms.CurrencyManager.EndCurrentEdit()在System.Windows.Forms.CurrencyManager.ChangeRecordState(的Int32在newPosition,布尔验证,布尔endCurrentEdit,布尔firePositionChange,布尔pullData)在System.Windows. Forms.CurrencyManager.UpdateIsBinding(布尔raiseItemChangedEvent)在System.Windows.Forms.CurrencyManager.UpdateIsBinding()在System.Windows.Forms.CurrencyManager.ResumeBinding()在System.Windows.Forms.BindingSource.ResumeBinding()在SomeProject.SomePanel. C:\ SomeDir\SomePanel.cs中的FlightData_DataReady():第94行
我们使用的是具有一些Nullable属性的简单对象模型.然而,并非所有人都试图捕捉塞特尔人/吸气者
我们正在使用DevExpress组件,在将属性更改为Nullable属性并将NullText属性添加到DevExpress文本框之后,会启动此特殊异常.
任何人都可以了解如何调试这种情况?
在解决了这个问题后,我注意到一些细节造成了这个问题.
其中一个Nullable双属性被绑定到具有Single属性的控件.数据绑定引擎抛出了一些关于无法将Nullable double转换为Single的第一个更改异常.
调试这个并找出哪个控件/属性应该被责备仍然是不可能的,任何人都有一些线索如何做到这一点?
Mar*_*tin 13
尝试启用格式化
this.myTextBox1.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", this.bindingSource1, "MyProperty", true));
Run Code Online (Sandbox Code Playgroud)
注意真参数
将此属性设置为true还会启用错误处理行为并导致引发BindingComplete事件.通过检查BindingCompleteEventArgs参数的BindingCompleteState属性,此事件的处理程序可以基于绑定过程中的成功,错误或异常采取适当的操作.
http://msdn.microsoft.com/en-us/library/system.windows.forms.binding.formattingenabled.aspx
| 归档时间: |
|
| 查看次数: |
4018 次 |
| 最近记录: |