Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TreeView Cleanup DropHighlight

Posted on 2004-08-10
5
Medium Priority
?
632 Views
Last Modified: 2007-11-27
My VB6 app lets users move nodes by drag and drop within the TreeView control.

But users may further drag the node outside the limits of the control - and drop it there, while the "no drop" dragicon is on.
In this case, how can the drophighlight be cleaned up? (Set tvTreeView.DropHighlight = Nothing)
Is there an event where I can put this code?
0
Comment
Question by:campinas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 400 total points
ID: 11761053
0
 
LVL 3

Expert Comment

by:TILL
ID: 11761231
Use this:

tvTreeView.Drag DragConstants.vbCancel

Best of luck,
TILL
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1600 total points
ID: 11763653
Yes there is...most people overlook the State parameter of the DragOver event:

    Private Sub TreeView1_DragOver(Source As Control, x As Single, y As Single, State As Integer)

    state: An integer that corresponds to the transition state of the control being dragged in relation to a target form or control:  
        0 = Enter (source control is being dragged within the range of a target).
        1 = Leave (source control is being dragged out of the range of a target).
        2 = Over (source control has moved from one position in the target to another).

So as you drag over a control you will initially get a state zero as you enter, followed by many state twos as you pass over potential
targets.  Finally, if you leave the control you will receive a state one.  So you simply need to modify your TreeView DragOver event
to unselect any highlighted items when you receive a state of one like this:

Private Sub TreeView1_DragOver(Source As Control, x As Single, y As Single, State As Integer)
    If Source.Name = "TreeView1" Then ' Only change DropHighlight if source is ourself
        Select Case State
            Case 0, 2 ' Dragged Moved Into or Within the TreeView
                Set TreeView1.DropHighlight = TreeView1.HitTest(x, y)
            Case 1 ' Dragged moved from Within to Outside the TreeView
                Set TreeView1.DropHighlight = Nothing
        End Select
    End If
End Sub

Regards,

Idle_Mind
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 11763818
Just a quick remark to the DragOver event, it might actually fail to raise, or be handled in "wrong" order by your application if the host is under stress and the user moving it's mouse quickly ...
Had this experience several times already. With subclassing, i solved that kind of problems (giving me other problem however :.(

CHeers
0
 

Author Comment

by:campinas
ID: 11767620
Idle_Mind, the Status parameter solution works perfectly for my app. Thanks a lot !  angelIII, thanks for the MouseLeave idea, it may help with other (non drag and drop) similar cases.

Cheers !
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

705 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