Link to home
Start Free TrialLog in
Avatar of sherrick123
sherrick123

asked on

List Box Drag and Drop Error

Hello,
I thought I had this done but I keep getting a error on my mouse down event.  Here is the Code I have.

This is how I am populated my First list box
 Private Sub cboFiles_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboFiles.SelectedIndexChanged
        Try
            Dim mySelDir As New DirectoryInfo(cboFiles.SelectedItem)
            Dim myFilename As FileInfo
            Dim myImageDir(1) As DirectoryInfo
            Dim myText As String

            myImageDir = mySelDir.GetDirectories("Images")

            lstDgnFiles.Items.Clear()
            lblOutPutDir.Text = myImageDir(0).FullName.ToString

            For Each myFilename In mySelDir.GetFiles("*.dgn")
                lstDgnFiles.Items.Add(myFilename)  'Add tostring to get out of the filename
            Next myFilename
        Catch ex As Exception
            MessageBox.Show("The process failed: {0}", ex.ToString())

        End Try

This is my code when I double click a file.  This works fine
  Private Sub lstDgnFiles_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstDgnFiles.DoubleClick

        lstMakePDF.Items.Add(lstDgnFiles.SelectedItem)

    End Sub


this Code i got from iboutchkine



 Private Sub lstDgnFiles_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstDgnFiles.MouseDown

        lstDgnFiles.DoDragDrop(lstDgnFiles.Items(lstDgnFiles.SelectedIndex.ToString()), DragDropEffects.Copy)

    End Sub

    Private Sub lstMakePDF_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstMakePDF.DragEnter
        If e.Data().GetDataPresent(DataFormats.Text) Then
            e.Effect() = DragDropEffects.Move
        Else
            e.Effect() = DragDropEffects.None
        End If
    End Sub

    Private Sub lstMakePDF_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstMakePDF.DragDrop
        lstMakePDF.SelectedItem = e.Data().GetData(DataFormats.Text).ToString()
    End Sub
End Class
ASKER CERTIFIED SOLUTION
Avatar of Lacutah
Lacutah
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sherrick123
sherrick123

ASKER

It still gives me a out of Range error????