Пример #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 (this.IsRowDragInProgress)
            {
                try
                {
                    ListViewItem dropItem;

                    dropItem = this.InsertionIndex != -1 ? this.Items[this.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 (this.InsertionMode == InsertionMode.After && dragItem.Index < this.Items.Count - 1)
                        {
                            dropIndex++;
                        }

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

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

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

            base.OnDragDrop(drgevent);
        }
Пример #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 OnItemDragDrop(ListViewItemDragEventArgs e)
        {
            EventHandler <ListViewItemDragEventArgs> handler;

            handler = this.ItemDragDrop;

            if (handler != null)
            {
                handler(this, e);
            }
        }