Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9074711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:42:04+00:00 2026-06-16T18:42:04+00:00

I have a tree view which is populated already with files/folders from another procedure.

  • 0

I have a tree view which is populated already with files/folders from another procedure. I would like to iterate one by one through the items in the tree view, going in exact order from top to bottom. However, unlike a normal list, I cannot use just a simple for statement for this. I have to go into each node, etc.

How do I do this? I’m hoping there’s a way I can do it without running a recursive procedure. As I iterate through these items, I don’t necessarily care about parent or child nodes of the currently focused one. I just need to be able to read the Data property of each node as I pass them, as well as highlight the current one in the tree view as I go through it. For each item in this tree view, I will be performing some work and want to visually display to the user which one is currently selected during this process.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:42:05+00:00Added an answer on June 16, 2026 at 6:42 pm

    In fact you can use a for loop.

    var
      Node: TTreeNode;
    ....
    for Node in TreeView.Items do
      DoSomething(Node);
    

    This is syntactic sugar for:

    for i := 0 to TreeView.Items.Count-1 do
      DoSomething(TreeView.Items[i]);
    

    In terms of readability I would recommend the for/in loop.

    In older Delphi versions that don’t support the node iterator you may prefer to do it with a while loop.

    Node := TreeView.Items.GetFirstNode;
    while Assigned(Node) do
    begin
      DoSomething(Node);
      Node := Node.GetNext;
    end;
    

    I expect there are other ways to do it. These are the only ones that I know!


    LU RD makes the interesting observation that the documentation states:

    Accessing tree view items by index can be time-intensive, particularly when the tree view contains many items. For optimal performance, try to design your application so that it has as few dependencies on the tree view’s item index as possible.

    This is quite true. For random access the code has to walk the tree, starting at the root, until the ith node is located.

    However, there is an optimisation for sequential access. The Delphi tree view wrapper remembers the index of the last node located by index. The next time you ask for a node with index no more than one different from the cached node, the required node can be returned quickly. This is implemented in TTreeNodes.GetNodeFromIndex.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tree view which has a folder icon by default and once
I have three tree view controls which house different (but mostly similar data), as
I have a tree view control which I have to bind a dataset with
I have to find the file names in tree view which has placed under
I have an app written in XUL which contains a custom tree view that
I have a treeview which is in detail view. listview is populated with items
Question: I have a view which I want to derive from a recursive query.
I have a tree view in which the ItemsSource is an ObservableCollection. I am
I had to populate a tree view for which i have made a custom
I have a tree view <asp:TreeView ID=TreeView1 runat=server DataSourceID=SiteMapDataSource1 ShowExpandCollapse=False> </asp:TreeView> As you can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.