//
        // OnDragOver event handler. Updates the dragged node's ghost image's position
        //
        protected override void OnDragOver(DragEventArgs drgevent)
        {
            base.OnDragOver(drgevent);

            // Cancel if no node is being dragged
            if (_draggedItems == null)
            {
                return;
            }

            // Get actual drop item
            Point controlP = PointToClient(new Point(drgevent.X, drgevent.Y));
            int   index    = InsertionMark.NearestIndex(controlP);

            if (index == -1)
            {
                return;
            }

            InsertionMark.Index = index;

            ListViewItem dropItem = Items[index];//GetItemAt(controlP.X, controlP.Y);

            if (dropItem != _tempDropItem)
            {
                ListViewItemDragEventArgs evArgs = new ListViewItemDragEventArgs(ListViewItemDragEventType.DragOver, ListViewItemDragEventBehavior.PlaceBeforeOrAfterAuto, _draggedItems, dropItem);

                if (DragOperation != null)
                {
                    DragOperation(evArgs);

                    // Cancel the operation if the user specified so
                    if (evArgs.Cancel)
                    {
                        drgevent.Effect = DragDropEffects.None;
                        OnDragDrop(drgevent);
                        return;
                    }
                    if (!evArgs.Allow)
                    {
                        return;
                    }
                }

                drgevent.Effect = DragDropEffects.Move;

                // Dissalow the drag here
                if (!evArgs.Allow)
                {
                    drgevent.Effect = DragDropEffects.None;
                }

                _tempDropItem = dropItem;
            }
        }
Beispiel #2
0
 public DragDropAssist(ListView listView)
 {
     fListView      = listView;
     fInsertionMark = new InsertionMark(fListView);
     fListView.PreviewMouseLeftButtonDown += ListView_PreviewMouseLeftButtonDown;
     fListView.PreviewMouseLeftButtonUp   += ListView_PreviewMouseLeftButtonUp;
     fListView.PreviewMouseMove           += ListView_PreviewMouseMove;
     fListView.DragOver          += ListView_DragOver;
     fListView.Drop              += ListView_Drop;
     fListView.QueryContinueDrag += ListView_QueryContinueDrag;
     fListView.AllowDrop          = true;
 }
Beispiel #3
0
        private void lv_DragOver(object sender, DragEventArgs e)
        {
            Point targetPoint = PointToClient(new Point(e.X, e.Y));
            int   targetIndex = InsertionMark.NearestIndex(targetPoint);

            if (targetIndex > -1)
            {
                Rectangle itemBounds = GetItemRect(targetIndex);
                EnsureVisible(targetIndex);

                if (targetPoint.Y > itemBounds.Top + (itemBounds.Height / 2))
                {
                    InsertionMark.AppearsAfterItem = true;
                }
                else
                {
                    InsertionMark.AppearsAfterItem = false;
                }
            }
            InsertionMark.Index = targetIndex;
        }
Beispiel #4
0
        protected override void OnDragOver(DragEventArgs drgevent)
        {
            base.OnDragOver(drgevent);
            Point        ptScreen = new Point(drgevent.X, drgevent.Y);
            Point        pt       = PointToClient(ptScreen);
            ListViewItem item     = GetItemAt(pt.X, pt.Y);

            int targetIndex = InsertionMark.NearestIndex(pt);

            if (targetIndex > -1)
            {
                Rectangle itemBounds = GetItemRect(targetIndex);
                if (pt.X > itemBounds.Left + (itemBounds.Width / 2))
                {
                    InsertionMark.AppearsAfterItem = true;
                }
                else
                {
                    InsertionMark.AppearsAfterItem = false;
                }
            }
            InsertionMark.Index = targetIndex;
        }