Solved

TreeView item search

Posted on 2000-04-21
4
240 Views
Last Modified: 2010-05-18
How to find a item in a TreeView component and expand the node?
0
Comment
Question by:SimonYu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 3

Accepted Solution

by:
shenqw earned 100 total points
ID: 2739476
procedure TForm1.Button1Click(Sender: TObject);
var
  i:integer;
  Node:TTreeNode;
begin
  TreeView1.AutoExpand:=True;
  for i:=0 to TreeView1.Items.Count-1 do
    if TreeView1.Items[i].Text='1234' then
    begin
      TreeView1.Selected:=TreeView1.Items[i];
      break;
    end;
end;
0
 
LVL 3

Expert Comment

by:shenqw
ID: 2739480
'1234' is your wanted selected node's Text
0
 

Author Comment

by:SimonYu
ID: 2740112
But how can I expand the selected item node only?
0
 
LVL 3

Expert Comment

by:shenqw
ID: 2740191
try follow:

procedure TForm1.Button1Click(Sender: TObject);
var
  i:integer;
begin
  for i:=0 to TreeView1.Items.Count-1 do
    if TreeView1.Items[i].Text='1234' then
    begin
      TreeView1.Items[i].Selected:=True;
      break;
    end;
end;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question