Autor Beitrag
Cäptin Pommes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 142
Erhaltene Danke: 2



BeitragVerfasst: Sa 04.06.11 12:02 
hi,

ich wollte Drag and Drop in meinen TreeView implementieren damit der user die TreeNodes verschieben kann.
ich habe mich an diesem beispiel gehalten support.microsoft.com/kb/307968/de

Nur leider funzt es nich ...

hier mal mein Code

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
         private void Checker_Load(object sender, EventArgs e)
        {
            this.treeView1.ItemDrag += new ItemDragEventHandler(treeView1_ItemDrag);
            this.treeView1.DragEnter += new DragEventHandler(treeView1_DragEnter);
            this.treeView1.DragDrop += new DragEventHandler(treeView1_DragDrop);

        }

        void treeView1_DragDrop(object sender, DragEventArgs e)
        {
            TreeNode newNode;

            if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode"false))
            {
                Point pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
                TreeNode DestinationNode = ((TreeView)sender).GetNodeAt(pt);
                newNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
                if (DestinationNode.TreeView != newNode.TreeView)
                {
                    DestinationNode.Nodes.Add((TreeNode)newNode.Clone());
                    DestinationNode.Expand();
                    
                    newNode.Remove();
                }
            }
        }

        void treeView1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Move;
        }

        void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
        {
            DoDragDrop(e.Item, DragDropEffects.Move);
        }


hoffe ihr könnt mir helfen :)
danke im vorraus
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4807
Erhaltene Danke: 1061

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Sa 04.06.11 12:40 
Hallo,

der Hinweis zu dem MSDN-Beitrag sagt ja auch:
MSDN hat folgendes geschrieben:
Der Code lässt z.B. keinen Drag&Drop-Vorgang mit Knoten im selben TreeView-Steuerelement zu.


Entferne daher mal die Abfrage
ausblenden C#-Quelltext
1:
if (DestinationNode.TreeView != newNode.TreeView)					
Cäptin Pommes Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 142
Erhaltene Danke: 2



BeitragVerfasst: Sa 04.06.11 23:47 
jut danke :) hat geholfen ^^