473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

TreeView drag and drop

Hi all,

I am trying to implement Drag and Drop with my TreeView Control. The problem is, when I click on a node, drag it, and drop it to other node. The dropped node does not hold the drop postion. It moves to the top of the nodes.

BTW, I am using VB6.0 here.

here is the codes

------------------
Private Sub TreeView1_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
Dim nodTarget As Node
Dim nodOrginal As Node
Set nodTarget = TreeView1.HitTest(x, y)
If Not (nodTarget Is Nothing) Then
Set TreeView1.SelectedItem.Parent = nodTarget
End If
End Sub
Private Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim nodNode As Node
Set nodNode = TreeView1.HitTest(x, y)
If nodNode Is Nothing Then Exit Sub '// no node
nodNode.Selected = True
End Sub
Private Sub TreeView1_OLEDragOver(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single, State As Integer)
Dim nodNode As Node
Effect = vbDropEffectMove
Set nodNode = TreeView1.HitTest(x, y)
If nodNode Is Nothing Or blnDragging = False Then
Effect = vbDropEffectNone
End If
End Sub
Private Sub TreeView1_OLEStartDrag(Data As MSComctlLib.DataObject, AllowedEffects As Long)
AllowedEffects = vbDropEffectMove
blnDragging = True
End Sub
------------------

Thanks
Egghead
Jul 17 '05 #1
1 18507

"EggHead" <ro******@shaw.ca> wrote in message
news:DlBue.76666$El.58850@pd7tw1no...
Hi all,

I am trying to implement Drag and Drop with my TreeView Control. The problem
is, when I click on a node, drag it, and drop it to other node. The dropped
node does not hold the drop postion. It moves to the top of the nodes.

BTW, I am using VB6.0 here.

here is the codes

------------------
Private Sub TreeView1_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As
Long, Button As Integer, Shift As Integer, x As Single, y As Single)
Dim nodTarget As Node
Dim nodOrginal As Node
Set nodTarget = TreeView1.HitTest(x, y)
If Not (nodTarget Is Nothing) Then
Set TreeView1.SelectedItem.Parent = nodTarget
End If
End Sub
Private Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, x As
Single, y As Single)
Dim nodNode As Node
Set nodNode = TreeView1.HitTest(x, y)
If nodNode Is Nothing Then Exit Sub '// no node
nodNode.Selected = True
End Sub
Private Sub TreeView1_OLEDragOver(Data As MSComctlLib.DataObject, Effect As
Long, Button As Integer, Shift As Integer, x As Single, y As Single, State
As Integer)
Dim nodNode As Node
Effect = vbDropEffectMove
Set nodNode = TreeView1.HitTest(x, y)
If nodNode Is Nothing Or blnDragging = False Then
Effect = vbDropEffectNone
End If
End Sub
Private Sub TreeView1_OLEStartDrag(Data As MSComctlLib.DataObject,
AllowedEffects As Long)
AllowedEffects = vbDropEffectMove
blnDragging = True
End Sub
------------------
Do you have the "sorted" property set to true? It should be true only during
load. Might also want to check after the drop..

Pseudocode..

ParentKey = TargetNode.Key

If ParentKey = "ROOT" Then
ParentKey = "0"
Else
ParentKey = Right$(ParentKey, Len(ParentKey) - 1)
End If

sKey = DragNode.Key
sKey = Right$(sKey, Len(sKey) - 1)

.DropHighlight = Nothing

If TargetNode.Key <> "ROOT" Then
TargetNode.ExpandedImage = "OPENFOLDER"
End If
If OldParentNode.Children <= 1 And OldParentNode.Key <> TargetNode.Key
Then
If OldParentNode.Key <> "ROOT" Then
OldParentNode.ExpandedImage = "CHILD"
OldParentNode.Image = "CHILD"
End If
End If
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Plumer | last post by:
Hello everyone, Yesterday I posted a message about implementing drag & drop in a TreeView control. I'm having real difficulty getting this to work -- the process seems to be incredibly...
1
by: Kevin Henkener | last post by:
I would like to be able to drag-n-drop System.Windows.Forms.TreeNode objects between two different applications (actually the same application, just two instances of it) in C#. I've seen posts in...
6
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview....
3
by: Kelvin Leung | last post by:
Hi I use Drag and Drop between 2 TreeView Control under VB.Net But I found that it cannot work when I add sub-class for each node Is it drag and drop method cannot work when the node with...
3
by: marc | last post by:
hello, I want to add scrolling and auto expanding after X msec to Drop & Drop in a treeview. Can someone me in the right direction. thanks Marc
0
by: Sarika | last post by:
Hi All, I migrated my VB 6.0 application to VB.NET. The original application had a tree view control whose elements could be dragged and dropped on a picturebox element. I am aware that the...
1
by: pooja | last post by:
i need to implement drag and drop in treeview in VB. Kindly help. My treeview contains activities maintained using XML Files. Hopefully, Thanks.
1
by: timnels | last post by:
I have created a muti-select treeview control. Problem is I am now trying to implement drag/drop in the application that uses it. It seems the mouse down and mouse move events fire before the...
0
by: munishbatra2002 | last post by:
hi all, we are using a gridview and a treeview control ... we want to drag a row from gridview control and drop it onto treeview control on a web page... we are using C# ASP.NET ... can anyone...
1
by: =?Utf-8?B?QW5kcmV3?= | last post by:
I am trying to adapt some code that I have where I drag and drop from two treeview controls. Now I want to drag and drop from a listview to a treeview. Whatever I do does not work and I cannot find...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.