Windows窗体应用程序异常 [英] Windows form application exception

查看:439
本文介绍了Windows窗体应用程序异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在System.Windows.Forms.CurrencyManager.get_Item(Int32索引)
中获得应用程序异常

I get application exception

   at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
   at System.Windows.Forms.CurrencyManager.get_Current()
   at System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs e)
   at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred)
   at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
   at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown)
   at System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)
   at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.DataGridView.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at MedForms.Program.Main() in F:\Projects\Vstu\MedForms\MedForms\Program.cs:line 18
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

每次当我尝试点击DataGridView。

each time when I try to click on DataGridView.

我收到错误消息


{索引-1不有一个值}
(SystemIndexOutOfaRange异常)。

{"Index -1 does not have a value."} (SystemIndexOutOfaRange exception).

在行

Application.Run(new MainForm());

,我无法调试。请帮助我找到可能导致这样的问题,以及如何调试?

and I am not able to debug it. Please help me find what can cause such problem and how I can to debug it?

推荐答案

我猜你已经绑定最初为空的列表(或不生成列表更改事件的其他类型的集合)到您的 DataGridView ,然后将项添加到此列表。

I'm guessing that you have bound a List that is initially empty, (or other sort of collection that does not generate list changed events) to your DataGridView, and then added items to this List.

您添加的项目将在网格上正确显示 ,但点击一行会导致此异常。这是因为底层的 CurrencyManager 会将其当前行位置报告为-1的偏移量。它将保持这种方式,因为列表不会报告对网格的更改。

The items you add will display correctly on your grid, but clicking on a row will cause this exception. This is because the underlying CurrencyManager will be reporting its current row position as an offset of -1. It will stay this way because the List does not report changes to the grid.

如果列表中有一些项目从头开始,您只应将其列表绑定到网格,或在您添加时重新绑定。

You should only bind your list to the grid if it has some items in it to begin with, or rebind when you add them.

另请参阅我的答案这个问题,这本质上是一样的问题。

See also my answer to this question, which is essentially the same problem.

这篇关于Windows窗体应用程序异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆