How can I enable and disable a item of a treeview?

Hello Guys

I am trying to work with treeview, It is some itens that I'd like to disable (enable = False), so that the user cannot have access.

Thanks
Alex
LVL 1
hidrauAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mahdi78Commented:
When create item put value 0 in StateIndex property and use the following even

procedure TForm1.FormCreate(Sender: TObject);
var I: integer;
begin
for I := 0 to TreeView1.Items.Count - 1 do
TreeView1.Items[I].Enabled := TreeView1.Items[I].StateIndex <> 0;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mahdi78Commented:
What you mean with can not access?
if you mean can not expand use OnExpanding even

procedure TForm1.TreeView1Expanding(Sender: TObject; Node: TTreeNode;
  var AllowExpansion: Boolean);
begin
AllowExpansion := Node.StateIndex <> 0;
end;
0
hidrauAuthor Commented:
Ok, I understood what you posted

I have a treeview this way:

products
   prod a
   prod b
   prod c
   prod d
clients
  clie 1
  clie 2
  clie 3
report
  rep 1
  rep 2
  rep 3

When I click on clie 2, My treeview must call another form. How can I get in the event onclick what option was clicked?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Mahdi78Commented:
There is many way, for you case use TTreeView.OnClick as following

procedure TForm1.TreeView1Click(Sender: TObject);
begin
if TreeView1.Selected.Text = 'clie 2' then Form2.Show;
end;
0
hidrauAuthor Commented:
thanks very much
0
Mahdi78Commented:
When you create item, you can Uncheck Enabled CheckBox of item
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.