我正在 .NET 4.0 中开发 Windows 窗体应用程序。当我将数据绑定到BindingSource
(其中一个ComboBox
已绑定),我得到以下异常。注意:只有当我让调试器在抛出异常(未处理或已处理)时停止时,我才会得到它。因此,异常在某个地方被捕获 - 但尽管如此,我不确定是否可以抛出异常。
发生 ArgumentOutOfRangeExceptionInvalidArgument=值“0”对于“SelectedIndex”无效。
参数名称:SelectedIndex
我没有设置SelectedIndex
财产。我的代码如下所示。myData
is an IList
实体数 (List
在运行时):
myBindingSource.DataSource = myData;
我不明白我做错了什么。此外,调用堆栈让我有点困惑(见下文)。 Windows 窗体框架似乎正在设置SelectedIndex
在组合框上,这会导致异常。有人知道摆脱这个的方法吗?
干杯
马蒂亚斯
System.Windows.Forms.dll!System.Windows.Forms.ComboBox.SelectedIndex.set(int value) + 0x233 bytes
System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.OnPositionChanged(System.EventArgs e) + 0x3e bytes
System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.ChangeRecordState(int newPosition, bool validating, bool endCurrentEdit, bool firePositionChange, bool pullData) + 0x1bd bytes
System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.List_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e) + 0x75c bytes
System.Windows.Forms.dll!System.Windows.Forms.BindingSource.ResetBindings(bool metadataChanged) + 0x3e bytes
System.Windows.Forms.dll!System.Windows.Forms.BindingSource.SetList(System.Collections.IList list, bool metaDataChanged, bool applySortAndFilter) + 0x22c bytes
System.Windows.Forms.dll!System.Windows.Forms.BindingSource.DataSource.set(object value) + 0x47 bytes
(my method)
当您要求调试器在出现异常时停止,无论异常是否会被处理,它都会这样做。这会导致类似您观察到的情况:
调试器在异常处停止并使您感到困惑,尽管该异常完全有效并且似乎是周围代码所期望的,因为它处理异常而不会死亡。
总结并回答你的问题:
并非调试器停止的所有异常都表明您做错了什么或代码中存在问题。
更新(感谢马克):
如果启用“仅我的代码”选项,您可以告诉调试器仅捕获您的异常。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)