Beispiel #1
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.DragDrop"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.DragEventArgs"/> that contains the event data. </param>
        protected override void OnDragDrop(DragEventArgs e)
        {
            base.OnDragDrop(e);

            Skill dragSkill = GetDraggingSkill(e);

            if (dragSkill != null)
            {
                return;
            }

            m_dragging = false;
            ClearDropMarker();
            if (!AllowRowReorder)
            {
                return;
            }

            if (SelectedItems.Count == 0)
            {
                return;
            }

            Point        cp         = PointToClient(new Point(e.X, e.Y));
            ListViewItem dragToItem = GetItemAt(cp.X, cp.Y);

            if (dragToItem == null)
            {
                return;
            }

            int dropIndex = dragToItem.Index;

            if (dropIndex > SelectedItems[0].Index)
            {
                dropIndex++;
            }

            if (ListViewItemsDragging != null)
            {
                ListViewDragEventArgs args = new ListViewDragEventArgs(SelectedItems[0].Index,
                                                                       SelectedItems.Count, dropIndex);
                ListViewItemsDragging(this, args);
                if (args.Cancel)
                {
                    return;
                }
            }

            // Make a copy of all the selected items
            ArrayList insertItems = new ArrayList(SelectedItems.Count);

            foreach (ListViewItem item in SelectedItems)
            {
                insertItems.Add(item.Clone());
            }

            // insert the copied items in reverse order at the drop index so
            // they appear in the right order after they've all been inserted
            for (int i = insertItems.Count - 1; i >= 0; i--)
            {
                Items.Insert(dropIndex, (ListViewItem)insertItems[i]);
            }

            // remove the selected items
            foreach (ListViewItem item in SelectedItems)
            {
                // must clear the items icon index or an exception is thrown when it is removed
                item.StateImageIndex = -1;
                Items.Remove(item);
            }

            ListViewItemsDragged?.ThreadSafeInvoke(this, new EventArgs());

            // if the item was dragged to the end of the plan.
            if (dropIndex >= Items.Count)
            {
                EnsureVisible(Items.Count - 1);
            }
            else
            {
                EnsureVisible(dropIndex);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.DragDrop"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.DragEventArgs"/> that contains the event data. </param>
        protected override void OnDragDrop(DragEventArgs e)
        {
            base.OnDragDrop(e);

            Skill dragSkill = GetDraggingSkill(e);
            if (dragSkill != null)
                return;

            m_dragging = false;
            ClearDropMarker();
            if (!AllowRowReorder)
                return;

            if (SelectedItems.Count == 0)
                return;

            Point cp = PointToClient(new Point(e.X, e.Y));
            ListViewItem dragToItem = GetItemAt(cp.X, cp.Y);
            if (dragToItem == null)
                return;

            int dropIndex = dragToItem.Index;
            if (dropIndex > SelectedItems[0].Index)
                dropIndex++;

            if (ListViewItemsDragging != null)
            {
                ListViewDragEventArgs args = new ListViewDragEventArgs(SelectedItems[0].Index,
                                                                       SelectedItems.Count, dropIndex);
                ListViewItemsDragging(this, args);
                if (args.Cancel)
                    return;
            }

            // Make a copy of all the selected items
            ArrayList insertItems = new ArrayList(SelectedItems.Count);
            foreach (ListViewItem item in SelectedItems)
            {
                insertItems.Add(item.Clone());
            }

            // insert the copied items in reverse order at the drop index so
            // they appear in the right order after they've all been inserted
            for (int i = insertItems.Count - 1; i >= 0; i--)
            {
                Items.Insert(dropIndex, (ListViewItem)insertItems[i]);
            }

            // remove the selected items
            foreach (ListViewItem item in SelectedItems)
            {
                // must clear the items icon index or an exception is thrown when it is removed
                item.StateImageIndex = -1;
                Items.Remove(item);
            }

            ListViewItemsDragged?.ThreadSafeInvoke(this, new EventArgs());

            // if the item was dragged to the end of the plan.
            if (dropIndex >= Items.Count)
                EnsureVisible(Items.Count - 1);
            else
                EnsureVisible(dropIndex);
        }