Solved

TreeView Cleanup DropHighlight

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
passing a value with stream reader AFTER a ";" 3 92
Crystal reports - Formula Field code need assistance with code 17 101
How to make an ADE file by code? 11 110
Problem to line 23 80
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

738 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