<p>I have a databound <code>DataGridView</code>. When a new row is added and the user presses <kbd>Esc</kbd> I want to delete the entire row. How can I do this?</p>

quite easy actually
```
```
private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)27)
    {
        if (dataGridView1.Rows.Count > 0)
        {
            dataGridView1.Rows.RemoveAt(dataGridView1.Rows.Count - 1);
            MessageBox.Show("Last row deleted!");
        }
        e.Handled = true;
    }
}
```
```
but take in mind that:
Rows cannot be programmatically removed unless the DataGridView is data-bound to an IBindingList that supports change notification and allows deletion