[英]Intercept key press delete
我的用戶組件中有一個列表視圖。 在listview屬性LabelEdit為true。 在listview上我有contextmenustrip項目刪除快捷鍵Del。我如何能夠按下按鍵Del如果編輯了一個單元格 - 刪除單元格中的文本,如果不可編輯 - 刪除Listview上的項目???
您可以通過綁定到ListView
上的KeyDown
(或KeyUp
)事件來開始簡單:
listView1.KeyDown += listView1_KeyDown;
然后在事件中:
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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.