I have a listview in my users component. On listview property LabelEdit is true. On listview i have contextmenustrip with item Delete with shortcut key Del. How can i catch key press Del that if a cell is edited - delete the text in the cell, if is not editable - delete Item on Listview???
You could start simple with binding to the KeyDown (or KeyUp) event on the ListView:
listView1.KeyDown += listView1_KeyDown;
And then in the event:
void listView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
// Check if selected item is editable and act accordingly...
// Bypass the control's default handling;
// otherwise, remove to pass the event to the default control handler.
e.Handled = true;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With