C# 关闭Form时出错:索引超出范围。必须为非负值并小于集合大小

llm320122 2012-03-23 05:03:44
System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index
在 System.Collections.ArrayList.get_Item(Int32 index)
在 System.Windows.Forms.DataGridViewColumnCollection.get_Item(Int32 index)
在 System.Windows.Forms.DataGridView.PositionEditingControl(Boolean setLocation, Boolean setSize, Boolean setFocus)
在 System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean useRowShortcut, Boolean computeVisibleRows, Boolean invalidInAdjustFillingColumns, Boolean repositionEditingControl)
在 System.Windows.Forms.DataGridView.ResetUIState(Boolean useRowShortcut, Boolean computeVisibleRows)
在 System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PreNotification(CollectionChangeAction cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow& dataGridViewRow, Boolean changeIsInsertion)
在 System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs e, Int32 rowIndex, Int32 rowCount, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
在 System.Windows.Forms.DataGridViewRowCollection.ClearInternal(Boolean recreateNewRow)
在 System.Windows.Forms.DataGridView.OnClearingColumns()
在 System.Windows.Forms.DataGridViewColumnCollection.Clear()
在 System.Windows.Forms.DataGridView.Dispose(Boolean disposing)
在 System.ComponentModel.Component.Dispose()
在 System.Windows.Forms.Control.Dispose(Boolean disposing)
在 System.ComponentModel.Component.Dispose()
在 System.Windows.Forms.Control.Dispose(Boolean disposing)
在 System.Windows.Forms.TabControl.Dispose(Boolean disposing)
在 System.ComponentModel.Component.Dispose()
在 System.Windows.Forms.Control.Dispose(Boolean disposing)
在 System.ComponentModel.Component.Dispose()
在 System.Windows.Forms.Control.Dispose(Boolean disposing)
在 System.Windows.Forms.Form.Dispose(Boolean disposing)
...全文
279 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
llm320122 2012-03-23
  • 打赏
  • 举报
回复
不好意思,,我是跟踪时才发现,dgv.Dispose();的时候就出现错误。

窗口关闭时系统会自动调用dgv.Dispose();的。
laichunlin 2012-03-23
  • 打赏
  • 举报
回复
这个错是DataGridView引起的,

数组越界,直接关闭窗体不用dgv.Dispose();

直接form.close();即可!
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 llm320122 的回复:]

没有啊。。窗口关闭时只写了dgv.Dispose();
[/Quote]
//容错
try
{
dgv.Dispose();
}
catch(Exception ex)
{

}
  • 打赏
  • 举报
回复
程序中可能出现了不规范的定义变量,也可能是多线程引起的。如果对程序没有影响,做过容错处理来屏蔽应该没问题。
llm320122 2012-03-23
  • 打赏
  • 举报
回复
没有啊。。窗口关闭时只写了dgv.Dispose();
bdmh 2012-03-23
  • 打赏
  • 举报
回复
关闭时,应该触发了一些onselectedchange之类的的事件,你断点看看

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧