Solved

TreeView Cleanup DropHighlight

Posted on 2004-08-10
5
624 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 143

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 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 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