Solved

right click & drag between 2 filelistboxes

Posted on 2003-11-19
4
405 Views
Last Modified: 2013-12-25
i am writing an application that basically has two explorer bars, just like
norton commander
im using vb6


its looking like this

side 1                             side 2
____________________________________________________________________
DRIVELISTBOX1                DRIVELISTBOX2

DIRLISTBOX1                             DIRLISTBOX2

FILELISTBOX1             FILELISTBOX2

______________________________________________________________________


the user obviously selects a drive on side 1 and then
selects a directory from dirlistbox1 and then
filelistbox1 displays everything in that directory.
very very simple.


PROBLEM:
the main reason i am writing this program is to be able to utilize TOTAL COPY.
i need  to be able to right click and drag a file from side 1 to side 2.
___________________________________________
in case you dont know total copy:
if you are in a windows explorer and you
right click and drag a file to any locaton, you
will get the options :
copy here
move here
cancel

if you have total copy installed , you get
2 extra options:

1)total move here
1)total copy here

___________________________________________

in windows i usually opened 2 explorers and tiled them vertically, but thats
why i am writing the app now.



any ideas on how i can accomplish this, i am totally lost :)

be able to right click and drag a file from a filelistbox to another filelistbox or dirlistbox

0
Comment
Question by:jxharding
  • 3
4 Comments
 
LVL 11

Expert Comment

by:dbrckovi
Comment Utility
Hi!

Does it realy have to be right button? When using right button on File list box, then it doesn't update ListIndex property (it doesn't select an item in that Listbox)
I'll give you an example of how it could work, with using left button for dragging.

On an empty form create the same structure as you noted in your question, and then just add a textbox somewhere and change its name to txtFilePath.

If you want, you can change File1's and File2's DragIcon property to some icon, becouse otherwise it will display a big rectangle when dragging.

Now paste this code:

---------------------------------------------------------------
Dim SideClicked As Integer

Private Sub Dir1_Change()
    File1 = Dir1
End Sub

Private Sub Dir2_Change()
    File2 = Dir2
End Sub

Private Sub Drive1_Change()
    Dir1 = Drive1
    File1 = Dir1
End Sub

Private Sub Drive2_Change()
    Dir2 = Drive2
    File2 = Dir2
End Sub

Private Sub File1_DragDrop(Source As Control, X As Single, Y As Single)
    Dim SourcePath As String
    Dim DestinationPath As String

    SourcePath = txtFilePath.Text
    DestinationPath = Dir1 & "\"

    If SideClicked = 2 Then MsgBox SourcePath & " copied to " & DestinationPath

    SideClicked = 0
End Sub

Private Sub File1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    SideClicked = 1
    File1.Drag
    txtFilePath = Dir1 & "\" & File1
End Sub

Private Sub File2_DragDrop(Source As Control, X As Single, Y As Single)
    Dim SourcePath As String
    Dim DestinationPath As String

    SourcePath = txtFilePath.Text
    DestinationPath = Dir2 & "\"

    If SideClicked = 1 Then MsgBox SourcePath & " copied to " & DestinationPath
    SideClicked = 0
End Sub

Private Sub File2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    SideClicked = 2
    File2.Drag
    txtFilePath = Dir2 & "\" & File2
End Sub

-------------------------------------------------------------------

Now when you click on any File list box and drag mouse to another, message will appear saying which file was copied to where.

I didn't implement any code for copiing becouse I'm not sure what you ment by 'total copy'.
If you could explain what is the difference between total copy and regular copy, then I could probably make function that would do the copiing.

If you already know how to make souch function then it  could be easily implemented in the above example just by replacing  "Msgbox  . . ." line with "TotalCopy (SourcePath, DestinationPath)"
0
 
LVL 11

Accepted Solution

by:
dbrckovi earned 250 total points
Comment Utility
The only sollution to implement a right button properly, that I could find is to first leftclick on a file to select it, and then use rightclick to drag it.

This is the same code as before changed so it can use right button for moving.

-------------------------------------------------------------------------
Dim SideClicked As Integer
Dim ButtonClicked As Integer

Private Sub Dir1_Change()
    File1 = Dir1
End Sub

Private Sub Dir2_Change()
    File2 = Dir2
End Sub

Private Sub Drive1_Change()
    Dir1 = Drive1
    File1 = Dir1
End Sub

Private Sub Drive2_Change()
    Dir2 = Drive2
    File2 = Dir2
End Sub



Private Sub File1_DragDrop(Source As Control, X As Single, Y As Single)
    Dim SourcePath As String
    Dim DestinationPath As String

    SourcePath = txtFilePath.Text
    DestinationPath = Dir1 & "\"
   
    If SideClicked = 2 And ButtonClicked = 2 Then
        MsgBox " Instead of me, call a form or popup which will provide options like:" _
                    & Chr(13) & "Copy" _
                    & Chr(13) & "Move" _
                    & Chr(13) & "Total Copy" _
                    & Chr(13) & "Total Move"
        Exit Sub
    End If

    If SideClicked = 2 Then MsgBox SourcePath & " copied to " & DestinationPath

    SideClicked = 0
    ButtonClicked = 0
End Sub

Private Sub File1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    On Error Resume Next
    If Button = 2 Then
        ButtonClicked = 2
    Else
        ButtonClicked = 1
    End If
   
    SideClicked = 1
    File1.Drag
    txtFilePath = Dir1 & "\" & File1
End Sub

Private Sub File2_DragDrop(Source As Control, X As Single, Y As Single)
    Dim SourcePath As String
    Dim DestinationPath As String

    SourcePath = txtFilePath.Text
    DestinationPath = Dir2 & "\"

    If SideClicked = 1 And ButtonClicked = 2 Then
        MsgBox " Instead of me, call a form or popup which will provide options like:" _
                    & Chr(13) & "Copy" _
                    & Chr(13) & "Move" _
                    & Chr(13) & "Total Copy" _
                    & Chr(13) & "Total Move"
        Exit Sub
    End If
    If SideClicked = 1 Then MsgBox SourcePath & " copied to " & DestinationPath
    ButtonClicked = 0
    SideClicked = 0
End Sub

Private Sub File2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    On Error Resume Next
    If Button = 2 Then
        ButtonClicked = 2
    Else
        ButtonClicked = 1
    End If
   
    SideClicked = 2
    File2.Drag
    txtFilePath = Dir2 & "\" & File2
End Sub
------------------------------------------------------------------

It is possible to make a right button to function exactly like left button, but in order to make it work you must write a function which will calculate an index of a selected file according to Mouse coordinate, scroll position, font size, type etc., and it is too painfull.

Personaly, I would use some other control to display files. One that can select its items with rightclick.
MSFlexGrid can be used for this.

Try this example to see how it could work:
Just add MSFlexgrid to your app and paste this code to designated Subs:
------------------------------------------------
Private Sub Form_Load()
    MSFlexGrid1.FixedCols = 0
    MSFlexGrid1.FixedCols = 0
    MSFlexGrid1.Rows = File1.ListCount
    MSFlexGrid1.Cols = 1
    MSFlexGrid1.Rows = File1.ListCount
    MSFlexGrid1.ColWidth(0) = MSFlexGrid1.Width
    MSFlexGrid1.GridColor = &HFFFFFF
   
    MSFlexGrid1.Col = 0
    For x = 0 To File1.ListCount - 1
        MSFlexGrid1.Row = x
        MSFlexGrid1.Text = File1.List(x)
    Next x
End Sub

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = 2 Then
        MSFlexGrid1.Row = MSFlexGrid1.MouseRow
        MsgBox MSFlexGrid1.Text
    End If
End Sub
----------------------------------------------
Now you just have to implement it to your code so it can act as Filelistbox. (Update it as File1 updates, etc.)

0
 

Author Comment

by:jxharding
Comment Utility
thanks a lot!
could you please take a look at this program ?

http://www.petri.co.il/software/total_copy_11.zip

its 70k, and its the bomb, id love to find out how this guy does this fast copying,
you must see the speed compared to normal copy!

answer brilliant
thanks again
0
 
LVL 11

Expert Comment

by:dbrckovi
Comment Utility
Thanx for accepting.

I'll try it and reply if I think of something, but i'm affraid that you won't get this in Visual Basic. That is; You won't get much faster copiing only with VB.
If you wish to speed it up then you should use C++ or some other lower-level programming language, even assembler, or you should find some dll, or Active X control which supports
Total Copy, or something simillar.

If the above program is freeware, then maybe contacting it's author could be usefoul. Maybe he/she alredy has souch routines, and is willing to give them.

Regards!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

10 Experts available now in Live!

Get 1:1 Help Now