473,811 Members | 3,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_OLEDr agDrop(Data As MSComctlLib.Dat aObject, 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.HitTe st(x, y)
If Not (nodTarget Is Nothing) Then
Set TreeView1.Selec tedItem.Parent = nodTarget
End If
End Sub
Private Sub TreeView1_Mouse Move(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim nodNode As Node
Set nodNode = TreeView1.HitTe st(x, y)
If nodNode Is Nothing Then Exit Sub '// no node
nodNode.Selecte d = True
End Sub
Private Sub TreeView1_OLEDr agOver(Data As MSComctlLib.Dat aObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single, State As Integer)
Dim nodNode As Node
Effect = vbDropEffectMov e
Set nodNode = TreeView1.HitTe st(x, y)
If nodNode Is Nothing Or blnDragging = False Then
Effect = vbDropEffectNon e
End If
End Sub
Private Sub TreeView1_OLESt artDrag(Data As MSComctlLib.Dat aObject, AllowedEffects As Long)
AllowedEffects = vbDropEffectMov e
blnDragging = True
End Sub
------------------

Thanks
Egghead
Jul 17 '05 #1
1 18536

"EggHead" <ro******@shaw. ca> wrote in message
news:DlBue.7666 6$El.58850@pd7t w1no...
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_OLEDr agDrop(Data As MSComctlLib.Dat aObject, 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.HitTe st(x, y)
If Not (nodTarget Is Nothing) Then
Set TreeView1.Selec tedItem.Parent = nodTarget
End If
End Sub
Private Sub TreeView1_Mouse Move(Button As Integer, Shift As Integer, x As
Single, y As Single)
Dim nodNode As Node
Set nodNode = TreeView1.HitTe st(x, y)
If nodNode Is Nothing Then Exit Sub '// no node
nodNode.Selecte d = True
End Sub
Private Sub TreeView1_OLEDr agOver(Data As MSComctlLib.Dat aObject, Effect As
Long, Button As Integer, Shift As Integer, x As Single, y As Single, State
As Integer)
Dim nodNode As Node
Effect = vbDropEffectMov e
Set nodNode = TreeView1.HitTe st(x, y)
If nodNode Is Nothing Or blnDragging = False Then
Effect = vbDropEffectNon e
End If
End Sub
Private Sub TreeView1_OLESt artDrag(Data As MSComctlLib.Dat aObject,
AllowedEffects As Long)
AllowedEffects = vbDropEffectMov e
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$(ParentKe y, Len(ParentKey) - 1)
End If

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

.DropHighlight = Nothing

If TargetNode.Key <> "ROOT" Then
TargetNode.Expa ndedImage = "OPENFOLDER "
End If
If OldParentNode.C hildren <= 1 And OldParentNode.K ey <> TargetNode.Key
Then
If OldParentNode.K ey <> "ROOT" Then
OldParentNode.E xpandedImage = "CHILD"
OldParentNode.I mage = "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
2283
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 delicately balanced and finding my way through it has descended into one of those awful situations which I refer to as guess & test. From the point at which DoDragDrop() function is called until some later
1
2543
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 which people advise that this process is no different the intra-application drag-n-drop process. I've had no luck with this concept. In fact, when I drag a node from application A's TreeView to application B's TreeView and call the GetData...
6
4935
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. However, either it only add it to the root level or it only add it on level below, doesn't matter what I select. And in some case, I just get an exception.
3
1426
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 sub-class ? If no, any related information/reference ? Thanks a lot
3
2792
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
1184
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 Drag drop functionality in .NET is different from that in VB 6.0. However, I did not get any upgrade warnings or errors to change the TreeView drag n drop. My application compiles and works but I am not able to get the treeview Drag n Drop to work.
1
1882
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
5019
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 OnBeforeSelect and OnAfterSelect events in the treeview. Since I want to start the drag/drop on the mouse move event, I have no clue that the current node has been selected yet. I tried moving all the code into the mouse down event (which actually...
0
1750
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 help how to drag and drop an item from gridview to treeview using javascript .. we are able to drop onto a particular area ( e:g a label), but itsn't possible to drop that item onto a particular node in treeview control ..
1
1950
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 any good articals on the net on how to do so. I have attached my original code for the two treeview controls. Can anybody point out where I need to make changes? Dim NewNode As Windows.Forms.TreeNode Dim imgIndex As Windows.Forms.TreeNode...
0
9724
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10394
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10127
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4336
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.