Exemplo n.º 1
0
        /// <summary>
        /// Handles dropping listviewitem for reordering
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lvRight_Drop(object sender, DragEventArgs e)
        {
            if (CanDragReorder)
            {
                RecordEntitySetting droppedData = e.Data.GetData(typeof(RecordEntitySetting)) as RecordEntitySetting;
                RecordEntitySetting target      = ((ListBoxItem)sender).DataContext as RecordEntitySetting;

                int sourcePos = SelectedList.IndexOf(droppedData);
                int destPos   = SelectedList.IndexOf(target);

                if (sourcePos < destPos)
                {
                    SelectedList.Insert(destPos + 1, droppedData);
                    SelectedList.RemoveAt(sourcePos);
                }
                else
                {
                    sourcePos++;

                    if (SelectedList.Count + 1 > sourcePos)
                    {
                        SelectedList.Insert(destPos, droppedData);
                        SelectedList.RemoveAt(sourcePos);
                    }
                }

                lvRight.ItemsSource = SelectedList.ToList();
                UpdateReorderButtons();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Move selected item down
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnMoveDown_Click(object sender, RoutedEventArgs e)
        {
            var list = from RecordEntitySetting item in this.lvRight.SelectedItems
                       orderby SelectedList.IndexOf(item) descending
                       select new Tuple <RecordEntitySetting, int>(item, SelectedList.IndexOf(item));

            foreach (var l in list)
            {
                SelectedList.Remove(l.Item1);
                SelectedList.Insert(l.Item2 + 1, l.Item1);
            }

            UpdateReorderButtons();
            UpdateListViews();
        }