ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

C# Drag and Drop fail

(1/1)

mediaguycouk:
Hi all, I'm doing really badly on my first try at a drag and drop. I'm trying to have a listBox that can have a file dragged onto it from Windows Explorer

From the very simple example here - http://support.microsoft.com/kb/307966 I have

Set AllowDrop on the list to TRUE
Set the event DragDrop
Set the event DragEnter

I have the following code


--- Code: C# ---private void listFilesToConvert_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)        {            // DEBUG            MessageBox.Show("DragEnter");             if (e.Data.GetDataPresent(DataFormats.FileDrop))                e.Effect = DragDropEffects.All;            else                e.Effect = DragDropEffects.None;        }         private void listFilesToConvert_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)        {            // DEBUG            MessageBox.Show("DragDrop");                        string[] s = (string[])e.Data.GetData(DataFormats.FileDrop);            int i;            for (i = 0; i < s.Length; i++)                listFilesToConvert.Items.Add(s[i]);         }
I can't say I understand it all, but it looks very similar to other code on the net. It's probably something simple but I can't work it out.

Neither debug message boxes fire.

Cheers

Graham R

fenixproductions:
2mediaguycouk
Works perfect here. Well... "almost perfect". Messago box has to be clicked and when I do so, dragged files are lost.

Maybe the reason is related to this somehow?

Use: Debug.WriteLine() for debugging and check will there be anything in Output panel.

PS. Check is it working inside your Visual Studio:
http://fenixproductions.republika.pl/tmp/test_drop.rar

mediaguycouk:
I shall thank Nutcase - http://channel9.msdn.com/forums/Coffeehouse/254293-c-Dragging-and-Dropping/

Visual Studio 2005 on Vista needs to run as administrator, explorer runs as a normal user. Vista doesn't allow programs using different privileges to interact.

So my code has worked for 3 hours :'(

(And thanks for the debug command, I didn't know it existed)

Navigation

[0] Message Index

Go to full version