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)

解决方案 »

  1.   

    关闭时,应该触发了一些onselectedchange之类的的事件,你断点看看
      

  2.   

    没有啊。。窗口关闭时只写了dgv.Dispose();
      

  3.   

    //容错
    try
    {
    dgv.Dispose();
    }
    catch(Exception ex)
    {}
      

  4.   

    这个错是DataGridView引起的,数组越界,直接关闭窗体不用dgv.Dispose();直接form.close();即可!
      

  5.   

    不好意思,,我是跟踪时才发现,dgv.Dispose();的时候就出现错误。窗口关闭时系统会自动调用dgv.Dispose();的。