The KeyPress
event needs the parameter KeyPressEventArgs
instead of KeyEventArgs
.
However the KeyPress
event only gives you the character of the key you pressed. And the DELETE key has no character. Therefor you should use the event KeyDown
instead, as this one is gives you the KeyCode instead:
this.listView.KeyDown+= new System.Windows.Forms.KeyPressEventHandler(this.listView_KeyDown);
private void listView_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
DeleteContact();
}
}