Solved

Help needed with TreeView

Posted on 2009-05-18
8
152 Views
Last Modified: 2012-05-07
Dear Experts,
I want to use a treeview, but i don't know nothing about it.
And i need to make my treeview working asap.
So there will be lots of points to be earned.

I have 2 buttons on the toolbar, one is for to create a node as a folder in the treeview
and 1 is to create a file in a treeview. For every node there is a window appearing
where the user can enter the filename or foldername.
How can I do that?

Greeting, PeterKiers



Example.jpg
0
Comment
Question by:peterkiers
  • 4
  • 4
8 Comments
 
LVL 1

Author Comment

by:peterkiers
ID: 24409886
send the wrong picture...
Examle.jpg
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 24410060
you need to add a TImageList (you other Q) with a Folder icon and a File icon


unit Unit1;
 

interface
 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ImgList;
 

type

  TForm1 = class(TForm)

    btnAddFolder: TButton;

    TreeView1: TTreeView;

    Edit1: TEdit;

    btnAddFile: TButton;

    ImageList1: TImageList;

    procedure btnAddFolderClick(Sender: TObject);

    procedure btnAddFileClick(Sender: TObject);

  private

    procedure AddItem(aText: string; aIndex: Integer; aParent: TTreeNode);

    { Private declarations }

  public

    { Public declarations }

  end;
 

var

  Form1: TForm1;
 

implementation
 

{$R *.dfm}
 

procedure TForm1.AddItem(aText: string; aIndex: Integer; aParent: TTreeNode);

var item: TTreeNode;

begin

  item := TTreeNode.Create(TreeView1.Items);

  item.Text := aText;

  item.ImageIndex := aIndex;

  item.SelectedIndex := aIndex;

  TreeView1.Items.AddNode(item, aParent, aText, nil, naAddChild);

end;
 

procedure TForm1.btnAddFileClick(Sender: TObject);

begin

  if (TreeView1.Selected <> nil) and (TreeView1.Selected.ImageIndex = 0) then

  begin

    AddItem(Edit1.Text, 1, TreeView1.Selected);

  end else

    ShowMessage('First select a folder');

end;
 

procedure TForm1.btnAddFolderClick(Sender: TObject);

begin

  AddItem(Edit1.Text, 0, nil);

end;
 

-- dfm --

object Form1: TForm1

  Left = 0

  Top = 0

  Caption = 'Form1'

  ClientHeight = 501

  ClientWidth = 520

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'Tahoma'

  Font.Style = []

  OldCreateOrder = False

  PixelsPerInch = 96

  TextHeight = 13

  object btnAddFolder: TButton

    Left = 352

    Top = 64

    Width = 75

    Height = 25

    Caption = 'Add folder'

    TabOrder = 0

    OnClick = btnAddFolderClick

  end

  object TreeView1: TTreeView

    Left = 24

    Top = 24

    Width = 306

    Height = 209

    Images = ImageList1

    Indent = 19

    TabOrder = 1

  end

  object Edit1: TEdit

    Left = 352

    Top = 32

    Width = 121

    Height = 21

    TabOrder = 2

    Text = 'Edit1'

  end

  object btnAddFile: TButton

    Left = 352

    Top = 96

    Width = 75

    Height = 25

    Caption = 'Add file'

    TabOrder = 3

    OnClick = btnAddFileClick

  end

  object ImageList1: TImageList

    Left = 464

    Top = 88

    Bitmap = {

      494C010102000400040010001000FFFFFFFFFF00FFFFFFFFFFFFFFFF424D3600

      0000000000003600000028000000400000001000000001002000000000000010

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF

      FF00000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000FFFF0000FFFF0000FFFF000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000FFFFFF0000000000000000000000000000000000FFFFFF00FFFFFF00FFFF

      FF00000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000FFFF0000FFFF00000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF

      FF00000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000FFFFFF00000000000000000000000000000000000000000000000000FFFF

      FF00000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF

      FF00000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000FFFFFF00000000000000000000000000000000000000000000000000FFFF

      FF00000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000FFFF0000FFFF0000FFFF000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF

      FF00000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000FFFF0000FFFF00000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000FFFFFF00000000000000000000000000FFFFFF00FFFFFF00FFFFFF00FFFF

      FF00000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF0000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000FFFFFF000000000000000000FFFFFF00FFFFFF0000000000FFFFFF000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF0000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000FFFF0000FFFF0000FF

      FF00000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000FFFF0000FFFF000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000424D3E000000000000003E000000

      2800000040000000100000000100010000000000800000000000000000000000

      000000000000000000000000FFFFFF00BFFFFFFF00000000BFFFE00700000000

      B049E00700000000807FE00700000000B07FE00700000000B9FFE00700000000

      BFFFE00700000000B049E00700000000807FE00700000000B07FE00700000000

      B9FFE00700000000BFFFE00F00000000048FE01F0000000007FFE03F00000000

      07FFFFFF000000009FFFFFFF00000000}

  end

end

Open in new window

0
 
LVL 1

Author Comment

by:peterkiers
ID: 24410130
Thank you for the solutions, it works great.
One litte question you have used a Edti1 on the form
where the user can enter a name for his file or folder.
but I want to have the edit1 on separate dialogform
is it possible to create one dynamicly or do i have
to create 2 forms.
P.
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24410640
did you try


procedure TForm1.btnAddFolderClick(Sender: TObject);

var aText: string;

begin

  if InputQuery('Folder', 'Enter a folder name', aText) then

    AddItem(aText, 0, nil);

end;

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:peterkiers
ID: 24411581
Thanks,
could you help me with the BtnFileClick
How do i have to implement it in the BtnFileClick procedure?

P.

0
 
LVL 1

Author Comment

by:peterkiers
ID: 24411604
Because i appreciate your help i will put it in a new question.

P.
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24411608
procedure TForm1.btnAddFileClick(Sender: TObject);
var aText: string;
begin
  if (TreeView1.Selected <> nil) and (Treeview1.Selected.ImageIndex = 0) then
  begin
    if InputQuery('File', 'Enter a file name', aText) then
      AddItem(aText, 1, TreeView1.Selectedl);
  end else
    ShowMessage('Select a folder in the treeview first.');
end;
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24411609
lol, not fast enough i guess
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

929 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now