[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 867
  • Last Modified:

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
0
hidrau
Asked:
hidrau
  • 4
  • 2
3 Solutions
 
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
 
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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
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

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now