title: Set DataGridView SelectedRows after Update
body: <p>In one of my C# Winform, I have a DataGridView that I update when the user presses a refresh button.</p>
  
  <p>The problem is that the selected row is lost in the process.</p>
  
  <p>I would like to be able to do the following:</p>
  
  <pre><code>private void function Refresh()
  {
  UpdateBegin(); // Keep the selected row in memory
  Update();
  UpdateEnd(); // Apply the selected row to the DataGridView
  }
  </code></pre>
  
  <p>Here is the Update function. It updates the data source, clears all the columns and bring back those that are required with the proper header text: </p>
  
  <pre><code>private void Update()
  {
      allItem = DataRepository.LotProvider.GetByIdProduit(detail.IdProduit)
  dataGridView1.DataSource = allItem;
  dataGridView1.Columns.Clear();
  // Get a dictionary of the required column ID / shown text
  Dictionary&lt;string, string&gt; dictionary = InitDisplayedFields();        
  foreach (KeyValuePair&lt;string, string&gt; column in dictionary)
      // If the grid does not contain the key
      if (!dataGridView1.Columns.Contains(column.Key))
      {
          // Add the column (key-value)
          int id = dataGridView1.Columns.Add(column.Key, column.Value);
          // Bind the property
          dataGridView1.Columns[id].DataPropertyName = column.Key;
      }
  
  }
  </code></pre>
  
  <p>However, the selected rows property of my DataGridView is Read-only. </p>
  
  <p>Is there a workaround to this ?</p>