?
Solved

drag and drop from one list box to another

Posted on 2004-11-19
3
Medium Priority
?
263 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:sherrick123
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
iboutchkine earned 1000 total points
ID: 12627871
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
 

Author Comment

by:sherrick123
ID: 12629425
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
 

Author Comment

by:sherrick123
ID: 12629599
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Loops Section Overview
Suggested Courses

807 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