当前位置: 代码迷 >> C# >> 用户代码未处理 System.ArgumentOutOfRangeException解决方法
  详细解决方案

用户代码未处理 System.ArgumentOutOfRangeException解决方法

热度:130   发布时间:2016-05-05 02:39:05.0
用户代码未处理 System.ArgumentOutOfRangeException
用户代码未处理 System.ArgumentOutOfRangeException
  Message=指定的参数已超出有效值的范围。
参数名: rowIndex
  Source=System.Windows.Forms
  ParamName=rowIndex
  StackTrace:
       在 System.Windows.Forms.DataGridViewRow.GetState(Int32 rowIndex)
       在 System.Windows.Forms.DataGridViewRow.get_Displayed()
       在 System.Windows.Forms.DataGridView.OnClearedRows()
       在 System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PostNotification(CollectionChangeAction cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow dataGridViewRow, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
       在 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.ComponentModel.Component.Dispose()
       在 System.Windows.Forms.Control.Dispose(Boolean disposing)
       在 System.Windows.Forms.ContainerControl.Dispose(Boolean disposing)
       在 System.ComponentModel.Component.Dispose()
       在 System.Windows.Forms.Control.Dispose(Boolean disposing)
       在 System.Windows.Forms.Form.Dispose(Boolean disposing)
       在 ZZ.App.Client.UI.MonitorMainForm.Dispose(Boolean disposing) 位置 C:\Documents and Settings\bxzz\桌面\客户端\ZzMonitorSolution\ZZ.App.Client.MonitorDemo\Main\MonitorMainForm.Designer.cs:行号 20
       在 System.ComponentModel.Component.Dispose()
       在 System.Windows.Forms.ApplicationContext.Dispose(Boolean disposing)
       在 System.Windows.Forms.Application.ThreadContext.DisposeThreadWindows()
  InnerException: 


   C#中 的问题,请教 怎么解决呀!
------解决思路----------------------
贴这么多没用的,啥也没描述出来。
在 ZZ.App.Client.UI.MonitorMainForm.Dispose(Boolean disposing) 位置 C:\Documents and Settings\bxzz\桌面\客户端\ZzMonitorSolution\ZZ.App.Client.MonitorDemo\Main\MonitorMainForm.Designer.cs:行号 20
去这里找找问题吧
------解决思路----------------------
意思是你这个rowindex超出了范围,实际上如果你要引用某一行的话,rowindex的有效范围应该是0~(RowCount-1),一旦发生引用.Rows[rowindex]而rowindex又超出这个范围的话,就会出现你这个异常。
原因有很多,可能你这个rowindex在使用时,指向的行已不存在,或者在Datagridview的事件中,e.RowIndex为-1(也就是由ColumnHeader触发的事件),具体原因你还是要追踪到MonitorMainForm.Designer.cs:行号 20这里来看。
下次发帖时,最好不要发这么多堆栈调用上来,堆栈调用是给你自己看的,而“Designer.cs:行号 20”附近的代码才是给我们看的
------解决思路----------------------
引用:
用户代码未处理 System.ArgumentOutOfRangeException
  Message=指定的参数已超出有效值的范围。
参数名: rowIndex
  Source=System.Windows.Forms
  ParamName=rowIndex
  StackTrace:
       在 System.Windows.Forms.DataGridViewRow.GetState(Int32 rowIndex)
       在 System.Windows.Forms.DataGridViewRow.get_Displayed()
       在 System.Windows.Forms.DataGridView.OnClearedRows()
       在 System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PostNotification(CollectionChangeAction cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow dataGridViewRow, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
       在 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.ComponentModel.Component.Dispose()
       在 System.Windows.Forms.Control.Dispose(Boolean disposing)
       在 System.Windows.Forms.ContainerControl.Dispose(Boolean disposing)
       在 System.ComponentModel.Component.Dispose()
       在 System.Windows.Forms.Control.Dispose(Boolean disposing)
       在 System.Windows.Forms.Form.Dispose(Boolean disposing)
       在 ZZ.App.Client.UI.MonitorMainForm.Dispose(Boolean disposing) 位置 C:\Documents and Settings\bxzz\桌面\客户端\ZzMonitorSolution\ZZ.App.Client.MonitorDemo\Main\MonitorMainForm.Designer.cs:行号 20
       在 System.ComponentModel.Component.Dispose()
       在 System.Windows.Forms.ApplicationContext.Dispose(Boolean disposing)
       在 System.Windows.Forms.Application.ThreadContext.DisposeThreadWindows()
  InnerException: 


   C#中 的问题,请教 怎么解决呀!

重点查对DataGridView有删除操作的代码
在使用Index的时候,先判定所涉及的元素是不是存在
--------------------
比如在遍历的过程中删除成员,则必然会导致ArgumentOutOfRangeException
------解决思路----------------------
说点实在话吧
既然你都已知错误类型了,怎么不这样去捕捉呢?
catch(System.ArgumentOutOfRangeException ex)
你就可以看到问题所在了
  相关解决方案