drag and drop from one list box to another

I was wanting to use the drag and drop option to add selected files from one listbox control to another.
i have the listbox set to multiselect.
I have it working now with a button the user has to press then of course i loop through all the selected items and add those to the other list box

Thanks
sherrick123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

iboutchkineCommented:
Here is an example to drag from listbox to textbox. Change it to listbox. the rest is the same


txtTemp AllowDrop set to True

Public Class fromMain
   Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

    Private Sub fromMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'This method sets application defaults

        'Object declarations
        Dim intIndex As Integer, strText As String = "This is item "

        'Populate the listbox
        For intIndex = 0 To 20
            lstTemp.Items().Add(strText & intIndex.ToString())
        Next
    End Sub

    Private Sub lstTemp_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstTemp.MouseDown
        lstTemp.DoDragDrop(lstTemp.Items(lstTemp.SelectedIndex()).ToString, DragDropEffects.Move)
    End Sub
    Private Sub txtTemp_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles txtTemp.DragEnter
        'Check the format of the incoming data and accept it if the destination control is able to handle
        '  the data format

        'Data verification
        If e.Data().GetDataPresent(DataFormats.Text) Then
            e.Effect() = DragDropEffects.Move
        Else
            e.Effect() = DragDropEffects.None
        End If

    End Sub

    Private Sub txtTemp_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles txtTemp.DragDrop
        'This procedure receives the dragged data once it passes the data verification handled by the DragEnter method

        'Drops the data onto the destination control
        txtTemp.Text() = e.Data().GetData(DataFormats.Text).ToString()

    End Sub
End Class
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sherrick123Author Commented:
it keep failing here is the code I took from yours.  The error is that it is out of range.  I get the erroro on the MouseDown event


 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.Move)
    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.FileDrop) Then
            e.Effect() = DragDropEffects.Move
        Else
            e.Effect() = DragDropEffects.None
        End If
    End Sub
0
sherrick123Author Commented:
Here is How I am populating the COPY FROM 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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.