Esempio n. 1
0
        // See if we should allow this kind of drag.
        private void treeView_DragEnter(object sender, DragEventArgs e)
        {
            TreeView tree = sender as TreeView;

            // Allow a Move for DragItem objects that are
            // dragged to the control that started the drag.
            if (!e.Data.GetDataPresent(typeof(DragItem)))
            {
                // Not a DragItem. Don't allow it.
                e.Effect = DragDropEffects.None;
            }
            else if ((e.AllowedEffect & DragDropEffects.Move) == 0)
            {
                // Not a Move. Do not allow it.
                e.Effect = DragDropEffects.None;
            }
            else
            {
                // Get the DragItem.
                DragItem drag_item = (DragItem)e.Data.GetData(typeof(DragItem));

                // Verify that this is the control that started the drag.
                if (drag_item.Client != listView1)
                {
                    // Not the congtrol that started the drag. Do not allow it.
                    e.Effect = DragDropEffects.None;
                }
                else
                {
                    // Allow it.
                    e.Effect = DragDropEffects.Move;
                }
            }
        }
Esempio n. 2
0
        // Drop the item here.
        private void tree_DragDrop(object sender, DragEventArgs e)
        {
            TreeView tree = sender as TreeView;

            // Get the ListBox item data.
            DragItem drag_item = (DragItem)e.Data.GetData(typeof(DragItem));

            // Get the index of the item at this position.
            TreeNode new_node = tree.NodeFromScreenPoint(new Point(e.X, e.Y));

            foreach (var item in drag_item.Items)
            {
                var category = Categories.getCategoryByPath(new_node.FullPath);
                item.Item.MoveCategory(category).Update();
            }

            // Select the item.
            tree.SelectedNode = new_node;
            treeView1_NodeMouseClick(tree, new TreeNodeMouseClickEventArgs(new_node, MouseButtons.Left, 1, e.X, e.Y));
        }
Esempio n. 3
0
        private void listBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (!isMouseDown || isDragAndDrop)
            {
                return;
            }

            var lst = sender as ListView;
            // Find the item under the mouse.
            //var point = lst.PointToClient(e.Location);
            //var index = lst.GetItemAt(point.X, point.Y) as ListItem;
            //lst.SelectedItems = new ListView.SelectedListViewItemCollection(lst) { index as ListItem; };
            //if (index < 0) return;

            // Drag the item.
            DragItem drag_item = new DragItem(lst, lst.SelectedItems.ToArray <ListItem>());

            lst.DoDragDrop(drag_item, DragDropEffects.Move);
            isDragAndDrop = true;
        }