title: Unable to Restore display index in datagridview
body: <p>So I have a class that I use to filter the results of a datagridview in vb.net. And one of the things I want this class to do, is keep the column order, width, and visibility. </p>
  
  <p>So what I do, is when my search class is instantiated, i create a copy of the columns in a hashtable, for later referencing.</p>
  
  <pre><code>Private dgv As DataGridView 
  Private dataSet As DataSet 
  Private bindingSource As New BindingSource
  
  Dim ht As New Hashtable()
  
  Public Sub new( ByRef dgv As DataGridView, ByVal dataSet As dataset )
  
      Me.dgv = dgv 
      Me.dataSet = dataSet 
  
      For Each col As DataGridViewColumn In dgv.Columns 
          ht.Add( col.headertext, col ) 
      Next
  
  End Sub
  </code></pre>
  
  <p>Then, I filter it like so...</p>
  
  <pre><code>Public Sub quickFilter( ByVal searchterm As string,  ByVal tablename As String, optional ByVal colname As string = Nothing )
  
      dgv.DataSource = dataSet 
      dgv.DataMember = tablename 
  
      bindingSource.DataSource = CType( dgv.DataSource, DataSet ).Tables.Item( tablename ) 
  
      bindingSource.Filter = determineColumnsFilter( searchterm, colname ) 
  
      dgv.DataSource = bindingSource.DataSource 
  
      restoreCols() 
  
  End Sub
  </code></pre>
  
  <p>The confusing part, is the restore cols function correctly restores width, and visibility, but not the display index. It seems to shuffle the columns around in any which way it chooses.</p>
  
  <pre><code>Private Sub restoreCols()
  
      For Each col As DataGridViewColumn In dgv.Columns 
  
          Dim colcopy As DataGridViewColumn = ht( col.headertext )
  
          col.Width = colcopy.Width 
          col.Visible = colcopy.Visible 
          col.DisplayIndex = colcopy.DisplayIndex 
  
      Next
  
  End Sub
  </code></pre>
  
  <p>Any idea why the display indexes don't restore properly?</p>
  
  <p>Thanks</p>