+ moveUp();\r
+ }\r
+ private void mnu_Down_Click(object sender, EventArgs e)\r
+ {\r
+ moveDown();\r
+ }\r
+ private void mnu_delete_Click(object sender, EventArgs e)\r
+ {\r
+ deleteSelectedItems();\r
+ }\r
+ private void btn_up_Click(object sender, EventArgs e)\r
+ {\r
+ moveUp();\r
+ }\r
+ private void btn_down_Click(object sender, EventArgs e)\r
+ {\r
+ moveDown();\r
+ }\r
+ private void btn_delete_Click(object sender, EventArgs e)\r
+ {\r
+ deleteSelectedItems();\r
+ }\r
+ private void list_queue_deleteKey(object sender, KeyEventArgs e)\r
+ {\r
+ if (e.KeyCode == Keys.Delete)\r
+ deleteSelectedItems();\r
+ }\r
+ private void moveUp()\r
+ {\r
+ // If there are selected items and the first item is not selected\r
+ if (list_queue.SelectedIndices.Count > 0 && !list_queue.SelectedIndices.Contains(0))\r
+ {\r
+ // Copy the selected indices to preserve them during the movement\r
+ List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);\r
+ foreach (int selectedIndex in list_queue.SelectedIndices)\r
+ selectedIndices.Add(selectedIndex);\r
+\r
+ // Move up each selected item\r
+ foreach (int selectedIndex in selectedIndices)\r
+ queue.MoveUp(selectedIndex);\r
+\r
+ updateUIElements();\r
+\r
+ // Keep the selected item(s) selected, now moved up one index\r
+ foreach (int selectedIndex in selectedIndices)\r
+ if (selectedIndex - 1 > -1) // Defensive programming: ensure index is good\r
+ list_queue.Items[selectedIndex - 1].Selected = true;\r
+ }\r
+\r
+ list_queue.Select(); // Activate the control to show the selected items\r
+ }\r
+ private void moveDown()\r
+ {\r
+ // If there are selected items and the last item is not selected\r
+ if (list_queue.SelectedIndices.Count > 0 &&\r
+ !list_queue.SelectedIndices.Contains(list_queue.Items[list_queue.Items.Count - 1].Index))\r
+ {\r
+ // Copy the selected indices to preserve them during the movement\r
+ List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);\r
+ foreach (int selectedIndex in list_queue.SelectedIndices)\r
+ selectedIndices.Add(selectedIndex);\r
+\r
+ // Reverse the indices to move the items down from last to first (preserves indices)\r
+ selectedIndices.Reverse();\r
+\r
+ // Move down each selected item\r
+ foreach (int selectedIndex in selectedIndices)\r
+ queue.MoveDown(selectedIndex);\r
+\r
+ updateUIElements();\r