Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to change the node order of a TTreeNode Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
26-Sep-02
Category
VCL-General
Language
Delphi 2.x
Views
62
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

Say I have a TOutline with these nodes:

Parent1
Node1
Node2
Node3
Parent2
Parent3

And I need to change the order of the nodes. How can I for example step Node2 down 
one step at a time and disable any movement when there are no more nodes to move 
past at that level (just after Node3). I need to restrict the stepping inside a 
group/ level and that it don't move to another parent.

Answer:

Look in the help file for the TTreeNode methods GetNextSibling, GetPrevSibling and 
MoveTo. Say you have a form with a tree view and two buttons, labelled up and down. 
The code for the onclick events of the up button would look something like this:

1   procedure UpOnClick
2   var
3     PrevSibling: TTreeNode;
4   begin
5     {If no node is selected, exit the procedure}
6     if MyTreeView.Selected = nil then
7       Exit;
8     {If the node the user is trying to move is not a child node, exit the procedure}
9     if MyTreeView.Selected.Level <> 1 then
10      Exit;
11    with MyTreeView.Selected do
12    begin
13      PrevSibling := GetPrevSibling;
14      if PrevSibling <> nil then
15        MoveTo(PrevSibling, naInsert);
16    end;
17  end;
18  
19  procedure DownOnClick
20  var
21    NextSibling: TTreeNode;
22  begin
23    {If no node is selected, exit the procedure}
24    if MyTreeView.Selected = nil then
25      Exit;
26    {If the node the user is trying to move is not a child node, exit the procedure}
27    if MyTreeView.Selected.Level <> 1 then
28      Exit;
29    with MyTreeView.Selected do
30    begin
31      NextSibling := GetNextSibling;
32      if NextSibling <> nil then
33        NextSibling.MoveTo(MyTreeView.Selected, naInsert);
34    end;
35  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC