title: DataGridView control must be bound to an IBindingList object to be sorted
body: <p>I have a custom control inherited from <code>DataGridView</code> that I'd like to be able to just copy the .cs file for, and drop it in to any project. There's one bit of code that I can't manage to move out of <code>Main.cs</code>, and into <code>DataGridView.cs</code> though:</p>
  
  <pre><code>private void Main_Load(object sender, EventArgs e)
  {
      dgv.Sort(dgv.Columns[0], ListSortDirection.Ascending);
      dgv.Columns[0].HeaderCell.SortGlyphDirection = SortOrder.Ascending;
  }
  </code></pre>
  
  <p>This is what I've tried:</p>
  
  <pre><code>class MyDataGridView : DataGridView
  {
      protected override void InitLayout()
      {
          base.InitLayout();
          Sort(Columns[0], ListSortDirection.Ascending);
          Columns[0].HeaderCell.SortGlyphDirection = SortOrder.Ascending;
      }
  
      // Lots of methods snipped
  }
  </code></pre>
  
  <p>The program immediately throws an <code>InvalidOperationException</code> on the <code>Sort()</code>:</p>
  
  <blockquote>
    <p>DataGridView control must be bound to an IBindingList object to be sorted.</p>
  </blockquote>
  
  <p>How can I move this code into <code>DataGridView.cs</code>?</p>