How to know if I am in the last row of a DataGridView

0

When I want to check if I find myself in the last row, I get an error

if (dgvClasificacion.CurrentRow.Index == dgvClasificacion.Rows.Count - 1)
        {
            dgvClasificacion.Rows.Add();

        }

Reference to object not established as instance of the object in the line of the if

    
asked by Pedro Ávila 01.05.2016 в 03:36
source

1 answer

1

By the message of the problem that you mention, it is safer that the CurrentRow is in null because there is no minguna row selected

if(dgvClasificacion.CurrentRow == null)
    return;

var lastRow = dgvClasificacion.Rows[dgvClasificacion.Rows.Count - 1];

if (dgvClasificacion.CurrentRow == lastRow)
{
    dgvClasificacion.Rows.Add();
}
    
answered by 01.05.2016 / 05:47
source