Exemple #1
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.DragDrop" /> event.
        /// </summary>
        /// <param name="drgevent">A <see cref="T:System.Windows.Forms.DragEventArgs" /> that contains the event data.</param>
        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            if (IsRowDragInProgress)
            {
                try
                {
                    ListViewItem dropItem;

                    dropItem = InsertionIndex != -1 ? Items[InsertionIndex] : null;

                    if (dropItem != null)
                    {
                        ListViewItem dragItem;
                        int          dropIndex;

                        dragItem  = (ListViewItem)drgevent.Data.GetData(typeof(ListViewItem));
                        dropIndex = dropItem.Index;

                        if (dragItem.Index < dropIndex)
                        {
                            dropIndex--;
                        }

                        if (InsertionMode == InsertionMode.After && dragItem.Index < Items.Count - 1)
                        {
                            dropIndex++;
                        }

                        if (dropIndex != dragItem.Index)
                        {
                            ListViewItemDragEventArgs args;
                            Point clientPoint;

                            clientPoint = PointToClient(new Point(drgevent.X, drgevent.Y));
                            args        = new ListViewItemDragEventArgs(dragItem, dropItem, dropIndex, InsertionMode, clientPoint.X, clientPoint.Y);

                            OnItemDragDrop(args);

                            if (!args.Cancel)
                            {
                                Items.Remove(dragItem);
                                Items.Insert(dropIndex, dragItem);
                                SelectedItem = dragItem;
                                OnItemDragDropCompleted(args);
                            }
                        }
                    }
                }
                finally
                {
                    InsertionIndex      = -1;
                    IsRowDragInProgress = false;
                    Invalidate();
                }
            }

            base.OnDragDrop(drgevent);
        }
Exemple #2
0
 /// <summary>
 /// Raises the <see cref="ItemDragDrop" /> event.
 /// </summary>
 /// <param name="e">The <see cref="ListViewItemDragEventArgs" /> instance containing the event data.</param>
 protected virtual void OnItemDragDropCompleted(ListViewItemDragEventArgs e)
 {
     ItemDragDropCompleted?.Invoke(this, e);
 }