views:

83

answers:

0

This method is used to handle KeyDown event of the listview:

 private void listView_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Control) 
            switch (e.KeyCode)
            {
                case Keys.A:
                    {
                        foreach (ListViewItem item in listView.Items)
                            item.Selected = true;

                        e.Handled = true;

                        break;
                    }
            }
    }

After an already selected item is clicked, pressing Ctrl+A selects all the items but after approx. 400 ms selection reverts to the item that was clicked.

Quick solution

public class CustomListView : ListView
{
    private const int WM_TIMER = 0x113;

    protected override void WndProc(ref Message m)
    {
        if (m.Msg != WM_TIMER)
            base.WndProc(ref m);
    }
}

Still there must be a proper way that's not so ugly.