Esempio n. 1
0
        /// <summary>
        ///     Is called when a drag-and-drop operation is completed in order to raise the Dropped event.
        /// </summary>
        /// <param name="e">Event arguments which hold information on the completed operation.</param>
        /// <remarks>
        ///     Is called for the target as well as for the source.
        ///     The role a control plays (source or target) can be determined from e.Operation.
        /// </remarks>
        public virtual void OnDropped(DroppedEventArgs e)
        {
            var dropEvent = Dropped;

            if (dropEvent != null)
            {
                dropEvent(this, e);
            }
        }
Esempio n. 2
0
        private void ListBoxDropped(object sender, DroppedEventArgs e)
        {
            for (int i = 0; i < listBox.Items.Count; i++)
            {
                var item = (PlaylistItem)listBox.Items[i];
                if (!item.Active)
                {
                    continue;
                }

                m_CurrentIndex = i;
                break;
            }
        }
Esempio n. 3
0
        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            base.OnDragDrop(drgevent);

            // Retrieve the drag item data.
            // Conditions have been testet in OnDragEnter and OnDragOver, so everything should be ok here.
            var src = drgevent.Data.GetData("IDragDropSource") as IDragDropSource;

            if (src == null)
            {
                return;
            }

            var srcItems = src.GetSelectedItems();

            // If the list box is sorted, we don't know where the items will be inserted
            // and we will have troubles selecting the inserted items. So let's disable sorting here.
            var sortedSave = Sorted;

            Sorted = false;

            // Insert at the currently hovered row.
            var row         = DropIndex(drgevent.Y);
            var insertPoint = row;

            if (row >= Items.Count)
            {
                // Append items to the end.
                Items.AddRange(srcItems);
            }
            else
            {
                // Insert items before row.
                foreach (var item in srcItems)
                {
                    Items.Insert(row++, item);
                }
            }
            // Remove all the selected items from the source, if moving.
            DropOperation operation; // Remembers the operation for the event we'll raise.

            if (drgevent.Effect == DragDropEffects.Move)
            {
                var adjustedInsertPoint = insertPoint;
                src.RemoveSelectedItems(ref adjustedInsertPoint);
                if (src == this)
                {
                    // Items are being reordered.
                    insertPoint = adjustedInsertPoint;
                    operation   = DropOperation.Reorder;
                }
                else
                {
                    operation = DropOperation.MoveToHere;
                }
            }
            else
            {
                operation = DropOperation.CopyToHere;
            }

            // Adjust the selected items in the target.
            ClearSelected();
            if (SelectionMode == SelectionMode.One)
            {
                // Select the first item inserted.
                SelectedIndex = insertPoint;
            }
            else if (SelectionMode != SelectionMode.None)
            {
                // Select the inserted items.
                for (var i = insertPoint; i < insertPoint + srcItems.Length; i++)
                {
                    SetSelected(i, true);
                }
            }

            // Now that we've selected the inserted items, restore the "Sorted" property.
            Sorted = sortedSave;

            // Notify the target (this control).
            var e = new DroppedEventArgs
            {
                Operation    = operation,
                Source       = src,
                Target       = this,
                DroppedItems = srcItems
            };

            OnDropped(e);

            // Notify the source (the other control).
            if (operation != DropOperation.Reorder)
            {
                e = new DroppedEventArgs
                {
                    Operation =
                        operation == DropOperation.MoveToHere ? DropOperation.MoveFromHere : DropOperation.CopyFromHere,
                    Source       = src,
                    Target       = this,
                    DroppedItems = srcItems
                };
                src.OnDropped(e);
            }
        }