Results 1 to 3 of 3

Thread: OLE Drag Drop and stuff

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2000
    Posts
    25

    Question

    I'm trying to drag an item from one list box to another and have the item be inserted in the destination list box in the right place. At first I used the ListView control and the HitTest method, which worked fine. But the ListView control doesn't have all the functionality that I need, so I gave up on it.

    Now I'm trying to use the ListBox; the only thing that seems to be missing is a function like HitTest that I can use to find the current list item based on the cursor position. I know that if I do some testing based on the topindex property, I could get past the problem. But that seems like it's a big work-around.

    Do any of you guys know an easy way of accomplishing this?

    Thanks!

    ______

    Bob K.

  2. #2
    Lively Member
    Join Date
    Jan 1999
    Posts
    81

    Here try this

    Here is a code example of a drag project... Hope it helps

    'Add Label, Drivebox,Dirbox,filebox


    Private Sub Form_Load()
    Picture1.AutoSize = -1 ' Turn on AutoSize.
    Label1.Visible = 0 ' Make the label invisible.
    File1.Pattern = "*.BMP; *.ICO; *.WMF" ' Set file patterns.
    End Sub

    Private Sub Dir1_Change() ' Any change in Dir1
    File1.Path = Dir1.Path ' is reflected in File1.
    End Sub

    Private Sub Drive1_Change() ' Any change in Drive1
    Dir1.Path = Drive1.Drive ' is reflected in Dir1.
    End Sub

    Private Sub File1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim DY ' Declare variable.
    DY = TextHeight("A") ' Get height of one line.
    Label1.Move File1.Left, File1.Top + Y - DY / 2, File1.Width, DY
    Label1.Drag ' Drag label outline.
    End Sub

    Private Sub Dir1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    ' Change pointer to no drop.
    If State = 0 Then Source.MousePointer = 12
    ' Use default mouse pointer.
    If State = 1 Then Source.MousePointer = 0
    End Sub

    Private Sub Drive1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    ' Change pointer to no drop.
    If State = 0 Then Source.MousePointer = 12
    ' Use default mouse pointer.
    If State = 1 Then Source.MousePointer = 0
    End Sub

    Private Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    ' Change pointer to no drop.
    If State = 0 Then Source.MousePointer = 12
    ' Use default mouse pointer.
    If State = 1 Then Source.MousePointer = 0
    End Sub

    Private Sub File1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    On Error Resume Next
    If State = 0 And Right$(File1.FileName, 4) = ".ICO" Then
    Label1.DragIcon = LoadPicture(File1.Path + "\" + File1.FileName)
    If Err Then MsgBox "The icon file can't be loaded."
    ElseIf State = 1 Then
    Label1.DragIcon = LoadPicture() ' Use no drag icon.
    End If
    End Sub

    Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
    On Error Resume Next
    Picture1.Picture = LoadPicture(File1.Path + "\" + File1.FileName)
    If Err Then MsgBox "The picture file can't be loaded."
    End Sub
    -------------------------
    There is never only one right answer. That is the magic of programming.
    -------------------------

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2000
    Posts
    25

    Wink

    Thanks...

    Before I looked at the replies, I made my own function to overcome the problem

    Code:
    Public Function LocateIndex(ListBoxControl as ListBox, X as single, Y as Single) as Integer
    I'll write the rest of the code in another reply.

    Thanks for your code, though. I'm trying to avoid the use of Drag Drop and rather use OLE Drag Drop. I don't know if a ListBox has the TextHeight method, either. You'll see my code pretty soon.

    Thanks!

    ______

    Bob K.

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