DataGridView placing the pointer in row created

1

At the moment of creating a row in a DataGridView I want the pointer to be in the new row created in the cell of the second column as I show in the imgagen.

Every time you create a new row, the cursor should be displayed in this way, ready to enter data.

I've tried this code but it does not do it like a real click

private void btnNuevoClasificacion_Click(object sender, EventArgs e)
    {
        if (dgvClasificacion.CurrentRow == null)
        {
            dgvClasificacion.DataSource = null;
            dgvClasificacion.Rows.Add();
            dgvClasificacion.CurrentRow.Cells[1].Selected = true;
        }
    
asked by Pedro Ávila 01.05.2016 в 18:07
source

1 answer

1

You should use the function BeginEdit() that has the object datagridview , with this the edition of the grid starts from the selected cell.

So after creating the row, you must make sure that the cell you want to edit is selected. When you add a row to a datagrid, it is put last, so you would have to select the cell you want from the last row.

Applied to your case:

...
dgvClasificacion.Rows.Add();
dgvClasificacion.CurrentCell = dgvClasificacion.Rows[dgvClasificacion.Rows.Count - 1].Cells[0];
dgvClasificacion.BeginEdit(true);

Accept as arguments:

  • true - > selecting the content that is in the cell
  • false - > without selecting the content in the cell

For your case, the argument is indifferent because there is no content in the cell when it is new.

    
answered by 01.05.2016 / 19:45
source