簡體   English   中英

攔截鍵按刪除

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM