I have a DGV in which I enter data directly but when I create a new row but I precede the escape key is pq I do not want to enter data but there is a blank row created then that row I want to delete, this is my code. Creating row.
private void btnNuevoClasificacion_Click(object sender, EventArgs e)
{
if (dgvClasificacion.CurrentRow == null)
{
dgvClasificacion.Rows.Add();
dgvClasificacion.CurrentRow.Cells[1].Selected = true;
dgvClasificacion.BeginEdit(true);
}
else
{
dgvClasificacion.Rows[dgvClasificacion.Rows.Count - 1].Selected = true;
dgvClasificacion.Rows.Add();
DataGridViewRowPosition(dgvClasificacion);
}
}
private void dgvClasificacion_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
dgvClasificacion.Rows[e.RowIndex].ErrorText = string.Empty;
ClasificacionTalla item = new ClasificacionTalla();
DataGridViewRow row = dgvClasificacion.CurrentRow;
item.Descripcion = Convert.ToString(row.Cells[1].Value);
if (!string.IsNullOrEmpty(item.Descripcion))
{
_repositoryClasificacionTalla.Create(item);
}
//else
// dgvClasificacion.Rows.Remove();
}
The idea is that if this row is empty, remove it by removing it, I have to pass the index of the last row to eliminate it. Any suggestions?