Results 1 to 2 of 2

Thread: Treeview Autoscroll Problem

  1. #1

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Treeview Autoscroll Problem

    Hi All,

    I have the following code to autoscroll a treeview while I am dragging an item. It works great. The problem is when I have the mouse in the areas where the autoscroll can take place and I don't select a place to drop the dragged item, the timer keeps running and the tree keeps scrolling even though I have stopped the dragging. How can I stop this.

    Code:
    Private Sub trvTree_OLEDragOver(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single, State As Integer)
    'Dim nodNode As Node
    Dim target As Node
    Dim highlight As Boolean
    
    On Error GoTo errh
    
        '// set the effect
        Effect = vbDropEffectMove
        '// get the node that the object is being dragged over
        Set target = trvTree.HitTest(x, y)
        mfX = x
        mfY = y
        If y > 0 And y < 100 Then 'scroll up
            m_iScrollDir = -1
            Timer2.Enabled = True
        ElseIf y > (trvTree.Height - 200) And y < trvTree.Height Then
            'scroll down
              m_iScrollDir = 1
              Timer2.Enabled = True
        Else
              Timer2.Enabled = False
        End If
    
        
        
        If target Is TargetNode Then Exit Sub
    
        Set TargetNode = target
    
        highlight = False
        If Not (TargetNode Is Nothing) And (blnDragging = True) Then
            '// the dragged object is not over a node, invalid drop target
            '// or the object is not from this control.
            If Mid(TargetNode.Key, 1, 1) = "c" Then
                highlight = True
            End If
    
            If highlight Then
                Set trvTree.DropHighlight = TargetNode
            Else
                Set trvTree.DropHighlight = Nothing
        End If
    
            Effect = vbDropEffectNone
        End If
    
    Exit Sub
    
    errh:
        errmsg "The following Exception occured : " & ERR.Description & ",  " & ERR.Source & "", "Exception occured in frmItemManager.trvTree_OLEDragOver()"
    
    End Sub
    Code:
    Private Sub Timer2_Timer()
    
    On Error GoTo errh
    
             Set trvTree.DropHighlight = trvTree.HitTest(mfX, mfY)
             If m_iScrollDir = -1 Then 'Scroll Up
             ' Send a WM_VSCROLL message 0 is up and 1 is down
               SendMessage trvTree.hWnd, 277&, 0&, vbNull
             Else 'Scroll Down
               SendMessage trvTree.hWnd, 277&, 1&, vbNull
             End If
    
    Exit Sub
        
    errh:
        errmsg "The following Exception occured : " & ERR.Description & ",  " & ERR.Source & "", "Exception occured in frmItemManager.Timer2_Timer()"
    
    End Sub

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Treeview Autoscroll Problem

    1 idea comes to mind. You may want to store the location of the mouse each time timer fires. Compare current mouse pos with previous pos & if it didn't change, +/- a couple of pixels, then don't scroll
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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