Note that there are some explanatory texts on larger screens.

plurals
  1. PODatagridView Select last row
    primarykey
    data
    text
    <p>I have some trouble with setting the last row in my datagridview selected. I select the last row this way:</p> <pre><code>if (grid.Rows.Count &gt; 0) { try { grid.Rows[grid.Rows.Count - 1].Selected = true; grid.CurrentCell = grid.Rows[grid.Rows.Count - 1].Cells[1] } catch (IndexOutOfRangeException) { } catch (ArgumentOutOfRangeException) { } } </code></pre> <p>When I execute this code I get an exception: <code>IndexOutOfRangeException occurred</code>: Index-1 does not have a value.</p> <p>When I debug the <code>Rows</code>collection and the corresponding <code>Cells</code> collection I see both collections are filled. The index also exists of the Rows and Cells collection.</p> <p>I have no clue what I am doing wrong here. Someone who can help me out here? Thnx</p> <p>EDIT:</p> <p>Here is the complete exception:</p> <pre><code>System.IndexOutOfRangeException: Index -1 does not have a value. at System.Windows.Forms.CurrencyManager.get_Item(Int32 index) at System.Windows.Forms.CurrencyManager.get_Current() at System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs e) at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell&amp; dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred) at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick) at System.Windows.Forms.DataGridView.set_CurrentCell(DataGridViewCell value) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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