473,394 Members | 1,854 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,394 software developers and data experts.

How can I order the nodes in a TreeView? (VB5)

Hello all

I am trying to write a specialist outlining tool, using the TreeView
control (in VB5 running on W95).

It has gone quite well so far. I have found some very useful info on
how to read and write tree structures to disk, and I've even figured
out how to cut, copy and paste branches of the tree. So, I'm fairly
pleased with progress.

But, I've got one major problem. The order of the nodes is important,
and I can't find a way to control this. I mean that, for my
application, this:

=Animals
==Cats
==Dogs
==Horses
==Giraffes

Is NOT equivalent to this:

=Animals
==Dogs
==Cats
==Horses
==Giraffes

The functionality I want (using the first example above) is to drag
'Giraffes' over 'Dogs' and release it, such that we now have:

=Animals
==Cats
==Dogs
==Giraffes
==Horses

Sounds simple, but I can't seem to find a way of controlling the order
of the nodes (except that their order seems to be the order in which
they are created. I suppose I could re-create the whole tree by
writing it to disk, deleting it, then re-reading it, every time there
is a drag and drop, but this seems a bit elaborate...).

Any help you can give me would be very much appreciated.

Thanks

Mr Chat
Jul 17 '05 #1
1 3472
It's not elegant, but this sort of code should do the trick:

Private Sub Command1_Click()
'add some test nodes
With TreeView1
Call .Nodes.Add(, , , "First")
Call .Nodes.Add(, , , "Second")
Call .Nodes.Add(, , , "Third")
End With
End Sub

Private Sub Command2_Click()
Dim oOldNode As Node
Dim oNewNode As Node

With TreeView1.Nodes
'get node #3
Set oOldNode = .Item(3)
'remove it from tree
Call .Remove(3)
'add a new node in front of #2, set key and text to old node
Set oNewNode = TreeView1.Nodes.Add(2, tvwPrevious, oOldNode.Key,
oOldNode.Text)
'set other properties as needed
oNewNode.Image = oOldNode.Image
'etc
End With

End Sub
"Mr Chat" <sa*****@richariya.freeserve.co.uk> wrote in message
news:54**************************@posting.google.c om...
Hello all

I am trying to write a specialist outlining tool, using the TreeView
control (in VB5 running on W95).

It has gone quite well so far. I have found some very useful info on
how to read and write tree structures to disk, and I've even figured
out how to cut, copy and paste branches of the tree. So, I'm fairly
pleased with progress.

But, I've got one major problem. The order of the nodes is important,
and I can't find a way to control this. I mean that, for my
application, this:

=Animals
==Cats
==Dogs
==Horses
==Giraffes

Is NOT equivalent to this:

=Animals
==Dogs
==Cats
==Horses
==Giraffes

The functionality I want (using the first example above) is to drag
'Giraffes' over 'Dogs' and release it, such that we now have:

=Animals
==Cats
==Dogs
==Giraffes
==Horses

Sounds simple, but I can't seem to find a way of controlling the order
of the nodes (except that their order seems to be the order in which
they are created. I suppose I could re-create the whole tree by
writing it to disk, deleting it, then re-reading it, every time there
is a drag and drop, but this seems a bit elaborate...).

Any help you can give me would be very much appreciated.

Thanks

Mr Chat

Jul 17 '05 #2

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

Similar topics

0
by: stardust | last post by:
Hi everyone, Within a Winform application, a treeview is contained in a User Control and the User Control is then located within a splitview. When the UserControl added some nodes into the...
10
by: John Rogers | last post by:
This code only counts the parent nodes or rootnodes in a treeview, how do you count all the nodes in a treeview? // one way int NodeCounter = 0; foreach (TreeNode currentNode in...
3
by: dutsnekcirf | last post by:
I have a treeview control on a custom task pane in Excel. I've enable the ability to use Drag & Drop (by following this how-to) on the treeview to change the order of the nodes. The problem though...
2
by: dutsnekcirf | last post by:
I found this article on how to nudge the treenode items up or down in the order of a treeview control. The problem is it's in C# and I know nothing about C#. In fact, C# scares me (I think it's the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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...
0
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...
0
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...

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.