Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This does so because you're resetting or reaffecting the DataSource property of your DataGridView control.</p> <p>In order to perform what you wish, you have to save the CurrentItem index into a local variable before resetting the DataSource property of your DataGridView. However, doing so implies that you know you're going to have the same or more amount of data, otherwise you will come out with an IndexOutOfRangeException trying to move to a greater index than the amount of data actually contained in your DataGridView.</p> <p>So, if you wish to save the index of your row or cell, you will need to make it through the DataGridView control properties as your BindingSource wil not deliver such feature. </p> <blockquote> <p>In a DataGridView, the selected row and the current row (indicated by an arrow in the row header) may not be the same row. In addition, we could select multiple rows in a DataGridView but the current row can only be one row. When the SelectionMode property of the DataGridView is set to FullRowSelect, the current row will be always selected. If you'd like to change the current row in a DataGridView control, you may set the CurrentCell property</p> </blockquote> <pre><code>dataGridView1.CurrentCell = dataGridView1.Rows[1].Cells[0]; </code></pre> <p>If you'd like to just change the selected row, you may set the Selected property of the row you want to true. </p> <pre><code>dataGridView1.CurrentRow.Selected = false; dataGridView1.Rows[1].Selected = true; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload