解决方案 »

  1.   

    感觉  你应该对obj 做个Null的判断
      

  2.   

    感觉应该是数据改动后没有刷新的问题
    当bindinglist中的值改变时触发这一事件,事件中写上
    dataGridView.RefreshEdit()刷新某单元格
    或者
    dataGridView.Refresh()全表刷新
    就不会出现数据改动滞后的现象。
      

  3.   


    移除的时候错误是肯定的,但移除不可能肯定是移除最后的一项,我这里用了BindingList<T>集合就是为了实时更新,
    更不可能在添加的时候才移除啦
      

  4.   


    null判断必须做了的,这里是精简的代码,想用最少的内容说明问题而已,这里的问题真心和对象是否null无关
      

  5.   

    在补充下错误异常日志:
    System.ArgumentOutOfRangeException: 提供的行索引超出范围。
    参数名: rowIndex
       在 System.Windows.Forms.DataGridViewRowCollection.GetRowState(Int32 rowIndex)
       在 System.Windows.Forms.DataGridView.OnRowGlobalAutoSize(Int32 rowIndex)
       在 System.Windows.Forms.DataGridView.OnRowHeightChanged(DataGridViewRowEventArgs e)
       在 System.Windows.Forms.DataGridView.OnBandThicknessChanged(DataGridViewBand dataGridViewBand)
       在 System.Windows.Forms.DataGridViewBand.set_ThicknessInternal(Int32 value)
       在 System.Windows.Forms.DataGridView.OnRemovedRow_PostNotification(DataGridViewRow dataGridViewRow, Point newCurrentCell)
       在 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.RemoveAtInternal(Int32 index, Boolean force)
       在 System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs e)
       在 System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(Object sender, ListChangedEventArgs e)
       在 System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
       在 System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
       在 System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
       在 System.ComponentModel.BindingList`1.FireListChanged(ListChangedType type, Int32 index)
       在 System.ComponentModel.BindingList`1.RemoveItem(Int32 index)
       在 System.Collections.ObjectModel.Collection`1.Remove(T item)