Adding a select all shortcut (Ctrl + A) to a .net listview?

前端 未结 5 497
野趣味
野趣味 2020-12-11 01:09

Like the subject says I have a listview, and I wanted to add the Ctrl + A select all shortcut to it. My first problem is that I can\'t figure out how

5条回答
  •  醉话见心
    2020-12-11 01:39

    The first solution won't work if user releases the Ctrl key first.

    You should use the KeyDown event instead:

    private void listView1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.A && e.Control)
        {
            listView1.MultiSelect = true;
            foreach (ListViewItem item in listView1.Items)
            {
                item.Selected = true;
            }
        }
    }
    

提交回复
热议问题