private void AddNewDelivery(string delivery)
        {
            if (IsNullOrWhiteSpace(delivery))
            {
                return;
            }
            m_listBoxDeliveries.SelectedItem = m_listBoxDeliveries.Items.Cast <AssignCharacterViewModel.Delivery>()
                                               .FirstOrDefault(d => d.Text == delivery);
            if (m_listBoxDeliveries.SelectedItem != null)
            {
                return;
            }
            var newItem = new AssignCharacterViewModel.Delivery(delivery);

            m_listBoxDeliveries.Items.Add(newItem);
            m_listBoxDeliveries.SelectedItem = newItem;
        }
        private void SelectDelivery(AssignCharacterViewModel.Delivery previouslySelectedDelivery)
        {
            if (m_listBoxCharacters.Items.Count == 0 || m_listBoxDeliveries.Items.Count == 0 || m_listBoxCharacters.SelectedItem == null)
            {
                return;
            }
            Block  currentBlock    = m_viewModel.CurrentBlock;
            string currentDelivery = IsNullOrEmpty(currentBlock.Delivery) ? AssignCharacterViewModel.Delivery.Normal.Text : currentBlock.Delivery;

            if (m_listBoxDeliveries.Items.Count == 1)
            {
                m_listBoxDeliveries.SelectedIndex = 0;
            }
            else
            {
                if (currentBlock.CharacterId == ((AssignCharacterViewModel.Character)m_listBoxCharacters.SelectedItem).CharacterId)
                {
                    foreach (var delivery in m_listBoxDeliveries.Items.Cast <AssignCharacterViewModel.Delivery>())
                    {
                        if (delivery.Text == currentDelivery)
                        {
                            m_listBoxDeliveries.SelectedItem = delivery;
                            return;
                        }
                    }
                }
                else if (m_listBoxDeliveries.Items.Count == 2)
                {
                    m_listBoxDeliveries.SelectedIndex = 1;                     // The first one will always be "Normal", so choose the other one.
                }
            }

            if (m_listBoxDeliveries.SelectedItem == null && previouslySelectedDelivery != null)
            {
                if (m_listBoxDeliveries.Items.Cast <AssignCharacterViewModel.Delivery>().Any(delivery => delivery == previouslySelectedDelivery))
                {
                    m_listBoxDeliveries.SelectedItem = previouslySelectedDelivery;
                }
            }
        }
        private void LoadDeliveryListBox(IEnumerable <AssignCharacterViewModel.Delivery> deliveries, AssignCharacterViewModel.Delivery selectedItem = null)
        {
            m_listBoxDeliveries.BeginUpdate();
            m_listBoxDeliveries.Items.Clear();

            foreach (var delivery in deliveries)
            {
                m_listBoxDeliveries.Items.Add(delivery);
            }

            SelectDelivery(selectedItem);
            m_listBoxDeliveries.EndUpdate();
        }