List Box Drag and Drop Error

Posted on 2004-11-23
Last Modified: 2010-04-23
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
            Dim mySelDir As New DirectoryInfo(cboFiles.SelectedItem)
            Dim myFilename As FileInfo
            Dim myImageDir(1) As DirectoryInfo
            Dim myText As String

            myImageDir = mySelDir.GetDirectories("Images")

            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


    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
            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
Question by:sherrick123
    LVL 9

    Accepted Solution

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

    Items is an array, access by integer index, so lstDgnFiles.SelectedIndex.ToString would not work because it's a String...

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

    Author Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now