title: C# Removing bindinglist item object on datagridview causes Exception
body: <p>I am very new to <code>C#</code>.</p>
  
  <p>I need to be able to remove objects from my <code>bindinglist</code> which is a data source for a <code>datagridview</code>. When I remove the last item I get the following exception:</p>
  
  <pre><code>System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Forms.DataGridViewRow.BuildInheritedRowStyle(Int32 rowIndex,              
  DataGridViewCellStyle inheritedRowStyle)
   at System.Windows.Forms.DataGridViewRow.Paint(Graphics graphics, Rectangle clipBounds,   
  Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean    isFirstDisplayedRow, Boolean isLastVisibleRow)
   at System.Windows.Forms.DataGridView.PaintRows(Graphics g, Rectangle boundingRect, 
  Rectangle clipRect, Boolean singleHorizontalBorderAdded)
   at System.Windows.Forms.DataGridView.PaintGrid(Graphics g, Rectangle gridBounds, 
  Rectangle clipRect, Boolean singleVerticalBorderAdded, Boolean singleHorizontalBorderAdded)
   at System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
   at System.Windows.Forms.Control.WmPaint(Message&amp; m)
   at System.Windows.Forms.Control.WndProc(Message&amp; m)
   at System.Windows.Forms.DataGridView.WndProc(Message&amp; m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  </code></pre>
  
  <p>Here's My Code for removing the object:</p>
  
  <p>studies is the bindinglist of study objects.</p>
  
  <pre><code>    private void removeComplete()
      {
  
          if (studies.Count == 0)
              return;
  
          // Create temp list of copleted studies
          List&lt;study&gt; completedStudies = studies.Where(s =&gt; s.isComplete() == true).ToList();
  
          if (studies.Count == 0)
          { 
             // do nothing
          }
          else
          {
              // If I don't use this line, every row produces the same exception 
              studies.RaiseListChangedEvents = false;
  
              foreach (study study in completedStudies)
              {
                  try
                  {
                      studies.Remove(study);
                  }
                  catch (Exception ex)
                  {
                      MessageBox.Show(ex.Message);
                  }
                  break;
              }
  
              // Turn it back on after turning it off above
              studies.RaiseListChangedEvents = true;
  
              // This is the point where it fails
              studies.ResetBindings();
          }
      }
  </code></pre>
  
  <p>From what I can see, the datagridview still seems to be attempting to add a row which has just been removed from the source. Which is really odd to me.</p>
  
  <p>Please help!</p>