Q:

Select then delete selected list items

I have some rows for which I want user to be able to select multiple by ctrl+a and after that can remove selected items by pressing the Delete key on the keyboard.
My code does not work. List items can be selected by ctrl+A but after pressing delete button, only one item will be deleted.
private void lvTasks_KeyDown(object sender, KeyEventArgs e)
{
     if (e.KeyCode == Keys.A && e.Control)
    {
        lvTasks.MultiSelect = true;
        foreach (ListViewItem item in lvTasks.Items)
        {
            item.Selected = true;
        }
    }
    if (e.KeyCode == Keys.Delete) 
    foreach (ListViewItem eachItem in lvTasks.SelectedItems)
    {
         DeleteTask();
    }
}

public void DeleteTask()
{
    if (lvTasks.SelectedItems.Count > 0)
    {

            lvTasks.Items.Remove(lvTasks.SelectedItems[0]);
            Statics.SaveTasks(lvTasks.Items.Cast<ListViewItem>().Select(l => (Task)l.Tag).ToArray());
            UpdateTaskProgress(new Task());
            txtDownloadLink.Text = "";
            txtRarPassword.Text = "";
            txtReferenceLink.Text = "";
            chkBackupResource.Checked = Properties.Settings.Default.BackupSource;
            chkClearExtracted.Checked = Properties.Settings.Default.CleanExtract;
            chkRemoveRar.Checked = Properties.Settings.Default.RemoveRar;
            chkUseIDM.Checked = Properties.Settings.Default.UseIDM;
            chkRemoveDownload.Checked = Properties.Settings.Default.RemoveDownload;
            gbTaskProgress.SuspendLayout();
            settings = Statics.LoadSettings();
            gbTaskProgress.Controls.Clear();
            int max = Enum.GetValues(typeof(TaskProgresses)).Cast<int>().LastOrDefault();
            for (int i = 0; i <= max; i++)
                gbTaskProgress.Controls.Add(new TaskProgress(i + 1) { Left = 10, Top = (20 + 24 * i), Caption = ((TaskProgresses)i).ToString().CapitalSplit(), Task = new Task() });
            gbTaskProgress.ResumeLayout();
            lvTasks.Items.Clear();
            Statics.LoadTasks().ToList().ForEach(t =>
            {
                ListViewItem lvi = new ListViewItem(new string[] { (lvTasks.Items.Count + 1).ToString(), t.TaskName, $"{t.TaskId}", $"{t.Progress}-{t.Status}" });
                t.UI = this;
                if (t.Status == TaskStatuses.Active) t.Status = TaskStatuses.NotStarted;
                lvi.Tag = t;
                lvi.SubItems[0].Tag = t.Progress;
                lvTasks.Items.Add(lvi);
            });

        }

}

A:

private void lvTasks_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.A && e.Control)
    {
     lvTasks.MultiSelect = true;
     foreach (ListViewItem item in lvTasks.Items)
     {
       item.Selected = true;
     }
    }
    if (e.KeyCode == Keys.Delete) 
    for (int i = lvTasks.SelectedItems.Count - 1; i >= 0; i--)
    {
     ListViewItem itm = lvTasks.SelectedItems[i];
     lvTasks.Items[itm.Index].Remove();
    }
}

EDIT
Your line lvTasks.Items.Remove(lvTasks.SelectedItems[0]); 
It's the problem. You are only deleting the item at index 0. You need to loop on them.
EDIT 2 It will only works if you want to delete all items. If you really want to delete only selected items. Change the for loop and delete the List : 
for (int i = lvTasks.SelectedItems.Count - 1; i >= 0; i--)
{
 ListViewItem itm = lvTasks.SelectedItems[i];
 lvTasks.Items[itm.Index].Remove();
}

That should works.

