Solved

TreeView Cleanup DropHighlight

Posted on 2004-08-10
5
618 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
5 Comments
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 100 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 85

Accepted Solution

by:
Mike Tomlinson earned 400 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 142

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

758 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

19 Experts available now in Live!

Get 1:1 Help Now