Audax321 Posted December 4, 2002 Posted December 4, 2002 VB6 had oleDragDrop, what is the equivalent in .NET and how do you use it? I have an application that searches user selected directories for files that match a search string. I want to allow the user to drag a line from the search results that appear in a listbox to another application. The drag must contain the path to the file being dragged. I've never really done any dragdrop in this manner in VB6 so I'm not very sure how to initialize a drag. Thanks for any help! :) Quote
*Gurus* Derek Stone Posted December 4, 2002 *Gurus* Posted December 4, 2002 Example The example below should get you going.windowsapplication2.zip Quote Posting Guidelines
Audax321 Posted December 5, 2002 Author Posted December 5, 2002 Okay, I got the drag to initialize. The problem I am having now is getting the drag into my other program which is made in VB6. The string containing the path is being dragged into a listview control on the other application. But, I'm getting the following error: Run-timer error '461': Specified format doesn't match format of data My other application accepts files using the data.files array. So is there anyway to get the path to be added to this when the drag is initialized? If not, then how do I get the other application to read the string? I'm not too sure what this error means. Quote
*Gurus* Derek Stone Posted December 5, 2002 *Gurus* Posted December 5, 2002 To be perfectly honest I've never used drag and drop across two different languages, so I'm not sure if it'll even work, especially due to the different nature of .NET. Are you passing the data using a text/string format and are you receiving the data using the same format? Quote Posting Guidelines
Audax321 Posted December 5, 2002 Author Posted December 5, 2002 Here is the code initializing the drag: Private Sub lstResults_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstResults.MouseDown If (lstResults.Items.Count > 0 And lstResults.SelectedIndex < lstResults.Items.Count) Then lstResults.DoDragDrop(lstPath.Items.Item(lstResults.SelectedIndex) & lstResults.Items.Item(lstResults.SelectedIndex), DragDropEffects.Copy) End If End Sub and here is the code that process the drag in the other program: Private Sub lstPlaylist_OLEDragOver(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single, State As Integer) If (Button = vbLeftButton) Then DragOpen = False Else DragOpen = True End If End Sub Private Sub lstPlaylist_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single) On Error GoTo Drophandler If (Data.Files.Count > 0) Then MsgBox ("drag initiated") For Each DragFile In Data.Files intstrsearch = InStr(1, DragFile, ".") Do While (intstrsearch < InStr(intstrsearch + 1, DragFile, ".")) If (intstrsearch < InStr(intstrsearch + 1, DragFile, ".")) Then intstrsearch = InStr(intstrsearch + 1, DragFile, ".") End If Loop strFileToOpen = Mid(DragFile, intstrsearch + 1, Len(DragFile)) If (strFileToOpen = "mp3" Or strFileToOpen = "mp2" Or strFileToOpen = "m3u" _ Or strFileToOpen = "mpg" Or strFileToOpen = "mpeg" Or strFileToOpen = "mpe" _ Or strFileToOpen = "mlv" Or strFileToOpen = "mpv2" Or strFileToOpen = "mp2v" _ Or strFileToOpen = "mpa" Or strFileToOpen = "cda" Or strFileToOpen = "au" _ Or strFileToOpen = "aif" Or strFileToOpen = "aifc" Or strFileToOpen = "aiff" _ Or strFileToOpen = "ivf" Or strFileToOpen = "wav" Or strFileToOpen = "avi" _ Or strFileToOpen = "mid" Or strFileToOpen = "midi" Or strFileToOpen = "rmi" _ Or strFileToOpen = "wmv" Or strFileToOpen = "wvx" Or strFileToOpen = "wma" _ Or strFileToOpen = "wax" Or strFileToOpen = "asf" Or strFileToOpen = "asx" _ Or strFileToOpen = "wm" Or strFileToOpen = "wmx" Or strFileToOpen = "wmp") Then strFileToOpen = DragFile If (DragOpen = False) Then Call CommandAddFiles End If If (DragOpen = True) Then Call CommandOpenFiles End If End If Next Data.Files.Clear End If Drophandler: MsgBox ("the drop was lost") End Sub I'm sure there is some way to do this, because it would be very counter productive for Microsoft to not allow .NET and VB6 applications to communicate in this way. The thing is that I really suck at this dragdrop stuff. I just wrote that code for the dragdrop procedure in the VB6 app a few days ago. It works great if you drag from Explorer, but I can't get it to work with the .NET application. Quote
Audax321 Posted December 5, 2002 Author Posted December 5, 2002 The drag is being initialized with a string but is being processed using drag.files which is an array of strings that point to paths to files. I have to get .NET to add its string to this array like Explorer does... I think :) Quote
Audax321 Posted December 5, 2002 Author Posted December 5, 2002 (edited) I figured it out.... I was assuming that visual basic would consider the dragged string a file because it was a path. Instead, I got it to work by having vb6 handle it as a string. Then to make sure that the string was a file, I just evaluted the following: len(dir(draggedstring)) If its not 0 then the program processes it. Hope it helps someone else... I was complicating things for myself for no good reason LOL :) Edited December 5, 2002 by Audax321 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.