Results 1 to 8 of 8

Thread: [2008] creating FTP client. DRAG DROP operations.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    [2008] creating FTP client. DRAG DROP operations.

    Hey guys,
    I am making a FTP client to be downloaded for free with the code available. However, I am have trouble creating a drag drop relation between the local file listbox and the remote file listbox.

    The local filelistbox is a listbox , but is extended to give it a "browser dialog" feel.

    The code project for this is http://www.codeproject.com/KB/select...esListBox.aspx

    I tried all of the drag/drop event handlers, and for some reason none of them fire. My c# is weak so i think it might be something missing from the extended one. for example, in vb theres "MyBase.new" but I dont see anything like that in the c# version of it.

    EDIT: I have converted the project to VB.NET and added mybase.new but it dosnt seem to do anything.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] creating FTP client. DRAG DROP operations.

    Here's an example on Drag and Drop functionallity between two listboxes containing strings:

    VB.NET Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         ListBox2.AllowDrop = True
    3.     End Sub
    4.  
    5.     Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
    6.         ListBox1.DoDragDrop(ListBox1.SelectedItem, DragDropEffects.Copy Or DragDropEffects.Move)
    7.     End Sub
    8.  
    9.     Private Sub ListBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragDrop
    10.         Dim droppedString As String = CType(e.Data.GetData("System.String"), String)
    11.         ListBox2.Items.Add(droppedString)
    12.     End Sub
    13.  
    14.     Private Sub ListBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragEnter
    15.         If e.Data.GetDataPresent("System.String") Then
    16.             e.Effect = DragDropEffects.Copy
    17.         End If
    18.     End Sub
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: [2008] creating FTP client. DRAG DROP operations.

    Thankyou for the code,
    I havnt tested it because i am at work, but a quick question. Will this allow multiple files to be selected and moved?

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] creating FTP client. DRAG DROP operations.

    no, you'd have to pass an array of all the selected items to the DoDragDrop method instead of just one selected item as I'm doing. You'd then have to treat the data as an array in the DragDrop eventhandler.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: [2008] creating FTP client. DRAG DROP operations.

    Alright thanks. But this raises a problem. Before I add the mousedown handler, i have the ability to select multiple files by dragging. But with the mousedown it just selects the file and goes into "move" mode.

    anyway to fix that?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] creating FTP client. DRAG DROP operations.

    The system can't read your mind to know whether you're dragging to select or dragging to move. What you could do is require that the Alt key be depressed while dragging to select. You can then test for that in the MouseDown event handler and only start a drag-n-drop operation if it's not.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: [2008] creating FTP client. DRAG DROP operations.

    Thankyou for the post. I was thinking of doing alternatives and whether its more usefull to select multiple files and click upload, or be able to select one file and upload.

    however, I am still wondering how most FTP's applications do it? I understand they may use a low level language such as c but I am thinking, that this is something that should be able to be done in vb.

    I will research it more, and if I do find a solution I will post it!@

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] creating FTP client. DRAG DROP operations.

    Most FTP applications I've seen don't support drag and drop to move files. They have two lists of files, one local and one remote, with two buttons in between to move selected files in each direction. That's most appropriate I think because dragging and dropping is actually more trouble than clicking a button. It also means they won't try to drop on a folder that is not the one they currently have open, which is a good thing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width