Question Drag Drop Files works in Visual Studio but fails in deployed version

nashwin

New member
Joined
Nov 26, 2014
Messages
4
Programming Experience
1-3
I have a windows application that can drag and drop files from File Explorer/Desktop into a listbox. It works fine in the Visual Studio Express 2013 environment in both debug and release builds. I have created an exe using Inno5 and when deployed as a stand-alone version - the drag and drop works for the first time but when it is shut down and opened again, all the drag and drop file functionality fails and the the copy effects are lost (Win 8). Extracting files from listbox also fails. I have been getting really frustrated with this and hope that some light might be shed on this issue? I have allowed drop in the listbox and the form and it fails on my desktop too (Win 7). Help would be very much appreciated.
 
There is nothing inherent in what you're trying to do that would cause that behaviour so the issue must be in the implementation. As you've given us no information about the implementation, we can give you no information about what's wrong with it. Please show us relevant code and explain EXACTLY what happens, which includes any relevant error messages and the exact behaviour of the code, i.e. where any course of execution or data value differs from what you expect.
 
Apologies, I'm new to this. The code below is used to be able to drag files in and out of a listbox. It works fine in the VS13Express environment. All drag drop functionality is lost after the first closing of the stand-alone deployed application.
    Private MouseDownPos As Point


    Private Sub lstGroups_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstGroups.MouseDown
        MouseDownPos = e.Location
        If chkReorder.Checked Then lstGroups.DoDragDrop(lstGroups.Text, DragDropEffects.Copy)
    End Sub


    Private Sub lstGroups_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstGroups.MouseMove
        If e.Button And MouseButtons.Left = MouseButtons.Left Then
            Dim dx = e.X - MouseDownPos.X
            Dim dy = e.Y - MouseDownPos.Y
            If Math.Abs(dx) >= SystemInformation.DoubleClickSize.Width OrElse Math.Abs(dy) >= SystemInformation.DoubleClickSize.Height Then
                If lstGroups.SelectedItems.Count > 0 Then
                    Dim strFilesPath() As String
                    ReDim strFilesPath(lstGroups.SelectedItems.Count - 1)
                    For i As Integer = 0 To lstGroups.SelectedItems.Count - 1
                        strFilesPath(i) = Application.StartupPath + "\Classlists\" + lstGroups.SelectedItems(i) + ".csv"
                    Next
                    Dim dt As DataObject = New DataObject(DataFormats.FileDrop, strFilesPath)
                    lstGroups.DoDragDrop(dt, DragDropEffects.Copy)
                End If
            End If
        End If
    End Sub


    Private Sub lstGroups_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstGroups.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub


    Private Sub lstGroups_DragOver(sender As Object, e As DragEventArgs) Handles lstGroups.DragOver
        e.Effect = DragDropEffects.Copy
    End Sub


    Private Sub lstGroups_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstGroups.DragDrop
        If chkReorder.Checked Then
            Dim ListIndex As Int32 = 0
            Dim Adjust As Int32 = 0
            ListIndex = lstGroups.IndexFromPoint(lstGroups.PointToClient(New Point(e.X, e.Y)))
            If ListIndex > lstGroups.SelectedIndex Then Adjust = 1
            If ListIndex >= 0 Then
                lstGroups.Items.Insert(ListIndex + Adjust, e.Data.GetData(DataFormats.Text))
                lstGroups.Items.RemoveAt(lstGroups.SelectedIndex)
                lstGroups.SelectedIndex = ListIndex
            End If
        Else
            If e.Data.GetDataPresent(DataFormats.FileDrop) Then
                Dim MyFiles() As String
                Dim i As Integer
                MyFiles = e.Data.GetData(DataFormats.FileDrop)
                For i = 0 To MyFiles.Length - 1
                    Try
                        DropFile(MyFiles(i))
                    Catch ex As Exception
                        MessageBox.Show(Me, "Filename already exists or incorrect file format.", "Import", MessageBoxButtons.OK)
                    End Try
                Next
            End If
        End If
    End Sub

There are no error messages, and all the DragDropEffects.Copy seem to turn to DragDropEffects.None? I just get the none effect on entry and drag drop is not performed where there should be and was a copy effect, and the code executed to perform the drag and drop perfectly. I have a number of controls in a few forms that all seem to lose the ability to drag and drop.
 
Last edited by a moderator:
Narrower

Looking into it further - it seems like it's the File.Copy that fails:

VB.NET:
                    For Each exportedFile As String In strFilesPath
                        MessageBox.Show(exportedFile + " " + ChosenFolder + "\" + Path.GetFileName(exportedFile))
                        Try
                            File.Copy(exportedFile, Path.Combine(ChosenFolder, Path.GetFileName(exportedFile)), True)
                            MessageBox.Show(exportedFile + " " + ChosenFolder + "\" + Path.GetFileName(exportedFile))
                        Catch copyError As IOException
                            Console.WriteLine(copyError.Message)
                        End Try
                    Next

Not sure why it fails at this point. I think this is why the drag-drop doesn't work?
 
Back
Top