Solved

Help needed with TreeView

Posted on 2009-05-18
8
151 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 36

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 36

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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 36

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 36

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

13 Experts available now in Live!

Get 1:1 Help Now