Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 04, 2016, 08:25:46 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: C# Drag and Drop fail  (Read 4550 times)

mediaguycouk

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 245
    • View Profile
    • Mediaguy
    • Donate to Member
C# Drag and Drop fail
« on: November 11, 2008, 12:30:41 PM »
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# [Select]
  1. private void listFilesToConvert_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
  2.         {
  3.             // DEBUG
  4.             MessageBox.Show("DragEnter");
  5.  
  6.             if (e.Data.GetDataPresent(DataFormats.FileDrop))
  7.                 e.Effect = DragDropEffects.All;
  8.             else
  9.                 e.Effect = DragDropEffects.None;
  10.         }
  11.  
  12.         private void listFilesToConvert_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
  13.         {
  14.             // DEBUG
  15.             MessageBox.Show("DragDrop");
  16.            
  17.             string[] s = (string[])e.Data.GetData(DataFormats.FileDrop);
  18.             int i;
  19.             for (i = 0; i < s.Length; i++)
  20.                 listFilesToConvert.Items.Add(s[i]);
  21.  
  22.         }

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
Learning C# - Graham Robinson

fenixproductions

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,184
    • View Profile
    • Donate to Member
Re: C# Drag and Drop fail
« Reply #1 on: November 11, 2008, 01:56:31 PM »
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://fenixproducti...pl/tmp/test_drop.rar
« Last Edit: November 11, 2008, 02:00:51 PM by fenixproductions »

mediaguycouk

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 245
    • View Profile
    • Mediaguy
    • Donate to Member
Re: C# Drag and Drop fail
« Reply #2 on: November 11, 2008, 02:00:16 PM »
I shall thank Nutcase - http://channel9.msdn...agging-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)
Learning C# - Graham Robinson