Coffeehouse Thread

9 posts

c# Dragging and Dropping

Back to Forum: Coffeehouse
  • User profile image
    Rich2k

    Having a real issue with C# 2005, tried everywhere and can't find a solution so far.  I've got quite a complex UI for an app but want to drag and drop from the IE addressbar to a tree control. 

    Now I'll be able to handle the actual dropped data, it's getting the drag drop to register that I can't solve.

    I've got AllowDrop set to true on the tree control, I've got a dragenter and dragdrop event and I've simply set e.Effect = DragDrop.Link

    Nothing happens.  I've changed it to change the status bar text just to try to get DragEnter to do anything, still nothing happens, no cursor changes, no status bar changes, nothing... just a black circle with a line through it.

    Anyone got any ideas?  I must be missing something simple but I don't know what.

  • User profile image
    Maddus Mattus

    I think the properties that you have set relate to dragging and dropping of tree leaves.

    But as to dragging and dropping from different controls, I have no clue. Never tried that.

    Sorry I cant be more helpfull.

  • User profile image
    Rich2k

    I thought so too but I thought I'd try to make it easy by doing a simple drag and drop from a text box on a webpage in IE to a text box control in the Windows Form, still nothing (and I've got example code from the web stating that it should be simple!)

  • User profile image
    NuTcAsE

    Drag Enter event handler:

    private void treeView1_DragEnter(object sender, DragEventArgs e)

    {

    if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy || (e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link)

    e.Effect = DragDropEffects.Link;

    }

    DragDrop Event handler:

    if (e.Effect == DragDropEffects.Link && e.Data.GetDataPresent(DataFormats.UnicodeText))

    {

    string newNode = e.Data.GetData (DataFormats.UnicodeText) as string;

    TreeNode node = new TreeNode(newNode);

    treeView1.Nodes.Add(node);

    }

    Ofcourse you could get fancy and handler DragOver event and track cursor movement to detect if the cursor is over an existing node to add the new node as a child.

  • User profile image
    Rich2k

    That's what I've done unfortunatey the form still ignores it.

    It was originally an upgrade from C# 2003 if that helps at all?

  • User profile image
    NuTcAsE

    Are you running Windows Vista? Are you debugging using VS 2005 with run as Admin?

    If so the drag and drop will not work when the application is started with Admin privleges. Content dragged from lower privilege apps, in this case IE, cannot be dropped on apps running with higher privileges.

    Don't ask me why that is... it just is. Spent a month figuring this out.

  • User profile image
    Rich2k

    Yeah it's on Vista with admin privliges.... I'll try compiling and running direct from the debug folder and see what happens.

  • User profile image
    AndyC

    NuTcAsE wrote:
    

    Don't ask me why that is... it just is. Spent a month figuring this out.


    User Interface Privilege Isolation. A drag-drop operation is often used to initiate action. If medium integrity applications could drop files onto high integrity ones they could potentially exploit that to initiate otherwise unwanted events at a high integrity level.

  • User profile image
    NuTcAsE

    AndyC wrote:
    
    NuTcAsE wrote: 

    Don't ask me why that is... it just is. Spent a month figuring this out.


    User Interface Privilege Isolation. A drag-drop operation is often used to initiate action. If medium integrity applications could drop files onto high integrity ones they could potentially exploit that to initiate otherwise unwanted events at a high integrity level.


    Well yeah that makes sense, and its good tha Vista's security features are covering all security vectors. My only gripe is I wish this information was more discoverable and I wouldnt have to waste a month figuring this out.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.