Solved

TreeView Cleanup DropHighlight

Posted on 2004-08-10
5
628 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 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 86

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
Suggested Courses
Course of the Month4 days, 15 hours left to enroll

635 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