Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Drag and Drop
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
Divers
Thread ID:
00694248
Message ID:
00694290
Vues:
14
Thanks Cathi,

I *finally* got it figured out ... I dug around in the news groups after I posted that question here and found code similar to what you've just posted (with some important differences). I needed both the PointToClient() and GetNodeAt() methods (as you mentioned), neither of which I had heard of before ... knowing how to use those got me pointed in the right direction.

Also, the fact that I put these to use in a different EventHandler might be relevant to someone ... I put it in the oTree_DragOver() EventHandler instead (because I needed to control not only what was being dragged into the Tree, but which Node it was being dragged to). Here's what I ended up doing there, in case anyone else needs help. Also, note that I had subclassed my TreeNode (I call them SideBarGroupNode) because I need to have some other Properties associated with each Node).
private void oTree_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
{
    Point pt;
    pt = this.oTree.PointToClient(new Point(e.X, e.Y));
    SideBarGroupNode node = (SideBarGroupNode)this.oTree.GetNodeAt(pt);
    if (node != null && node.IsGroupNode == true)
    {
        if (node.IsExpanded == false)
            node.Expand();
        this.oTree.SelectedNode = node;
        e.Effect = DragDropEffects.All;
    }
    else
        e.Effect.DragDropEffects.None;   
    }
}
There's a few more lines of code in there, but that's the relevant stuff. Then the oTree_DragDrop() EventHandler actually adds the node to the node collection of oTree.SelectedNode, the above code just determines when and where it should be added. One thing should be noted ... at least as far as I was able to determine ... this EventHandler (DragOver) was the only one that returned the e.X and e.Y coordinates associated with where the object was being dragged TO. For every other Drag event, the coordinates seemed to be for where the object was being dragged from.


~~Bonnie

>Hi Bonnie,
>
>I saw this bit of code a while ago and saved it for when I needed similar functionality. I haven't tried it and it is written VB.NET but see if it will work for you:
>
>
>Private Sub TreeView1_DragDrop(ByVal sender As Object, ByVal e As
>System.Windows.Forms.DragEventArgs) Handles TreeView1.DragDrop
>      Dim oNode As TreeNode
>      oNode = TreeView1.GetNodeAt(TreeView1.PointToClient(New Point(e.X,
>e.Y)))
>      oNode.Nodes.Add(e.Data.GetData(DataFormats.Text).ToString)
>End Sub
>
>
>>Anyone doing much with drag-and-drop? I'm trying to get a control on a Windows form to work. I have a TreeView on the left side, a ListView on the right ... your typical Windows Explorer type of control. I want to drag icons between the two. I've got it sort of working. I can drag icons in either direction, adding and removing them from either the TreeView or the ListView as needed. But, so far I haven't figured out how to drop a ListViewItem into any node of the Tree. I have only been able to drop it into whichever node is already selected. Obviously not all that intuitive for the user. I need to be able to expand a node if it is not already expanded and/or to have it become the selected node if the mouse hovers over it.
>>
>>I can't for the life of me figure out how to do this. The MouseHover() eventhandler is probably where this code goes, but I can't figure it out and I haven't been able to find any examples.
>>
>>Help!
>>
>>TIA,
>>~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform