Example #1
0
        private void TodoCheckListBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up)
            {
                int index = TodoCheckListBox.SelectedIndex;

                if (index > 0)
                {
                    TodoItem item = (TodoItem)TodoCheckListBox.SelectedItem;
                    todoList.Remove(item);
                    todoList.Insert(index - 1, item);
                    todoList[index - 1].Priority -= 1;
                    todoList[index].Priority     += 1;
                    TodoCheckListBox.SetSelected(index, true);
                }
            }

            if (e.KeyCode == Keys.Down)
            {
                int index = TodoCheckListBox.SelectedIndex;

                if (index < todoList.Count - 1)
                {
                    TodoItem item = (TodoItem)TodoCheckListBox.SelectedItem;
                    todoList.Remove(item);
                    todoList.Insert(index + 1, item);
                    todoList[index + 1].Priority += 1;
                    todoList[index].Priority     -= 1;
                    TodoCheckListBox.SetSelected(index, true);
                }
            }
        }