Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Treeview question

Posted on 2009-05-18
8
Medium Priority
?
186 Views
Last Modified: 2012-05-07
Dear experts,

I have received a code from an expert and it works just fine.
But with this code your not able to create a folder in a folder.

What do I have to change:

Peter Kiers
(*----------------------------------------*)
procedure TMainForm.NewFolder1Click(Sender: TObject);
var aText: string;
begin
  if InputQuery('New Folder', 'New Folder Name:', aText) then
    AddItem(aText, 0, nil);
end;
(*----------------------------------------*)
procedure TMainForm.NewItem1Click(Sender: TObject);
var aText: string;
begin
  if (TreeView1.Selected <> nil) and (Treeview1.Selected.ImageIndex = 0) then 
  begin
    if InputQuery('New Item', 'New Item Name:', aText) then
      AddItem(aText, 1, TreeView1.Selected);
  end else 
    ShowMessage('Select a folder in the treeview first.');
end;
(*----------------------------------------*)
procedure TMainForm.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;

Open in new window

0
Comment
Question by:peterkiers
[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
  • 4
  • 4
8 Comments
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24411817
procedure TMainForm.NewFolder1Click(Sender: TObject);
var aText: string;
  aParent: TTreeNode;
begin
  if InputQuery('New Folder', 'New Folder Name:', aText) then
  begin
    aParent := nil;
    if TreeView1.Selected <> nil then
      case MessageDlg('Do you want to create the folder below the currently selected one (no = create at toplevel, yes = create below selected)', mtConfirmation, [mbOk, mbNo, mbCancel], 0) of
        mrYes: aParent := TreeView1.Selected;
        mrNo: ; // aParent := nil;
        mrCancel: Exit;
      end;
    AddItem(aText, 0, aParent);
  end;
end;
0
 
LVL 1

Author Comment

by:peterkiers
ID: 24411881
Code doesn't work, and a don't want the qeustion to be ask
so no messagedlg.

Gtrx, PK
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24412181
sorry, didn't test in Delphi, just typed it in firefoxy
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);
var aText: string;
begin
  if InputQuery('Folder', 'Enter a folder name', aText) then
    AddItem(aText, 0, nil);
end;
 
procedure TForm1.btnAddSubFolderClick(Sender: TObject);
var aText: string;
begin
  if (TreeView1.Selected <> nil) and (TreeView1.Selected.ImageIndex = 0) then
  begin
    if InputQuery('New Sub Folder', 'New Sub Folder Name:', aText) then
      AddItem(aText, 0, TreeView1.Selected);
  end else 
    ShowMessage('You must select a folder first !');
end;

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:peterkiers
ID: 24412271
You made for adding a subfolder in a folder a new button
But I want to use the same add folder button
and I know its possible.
I have send an example.

Greetings, Peter Kiers
Naamloos.jpg
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24412379
okay, both of them into 1 with no messagedlg (check is on selected folder)


procedure TForm1.btnAddFolderClick(Sender: TObject);
var aText: string;
  aParent: TTreeNode;
begin
  aParent := nil;
  if TreeView1.Selected <> nil then 
  begin
    if TreeView1.Selected.ImageIndex = 0 then // check for folder
      aParent := TreeView1.Selected
    //else 
    //begin
    //  ShowMessage('Select a folder first');
    //  Exit;
    //end;
    // uncomment previous 5 lines if a file is selected and you only want this to add on selected folders
  end;
  if InputQuery('Folder', 'Enter a folder name', aText) then
    AddItem(aText, 0, aParent);
end;

Open in new window

0
 
LVL 1

Author Comment

by:peterkiers
ID: 24412451
Much better, only the new created subfolder will not automaticly collapse
you have to press the + sign to see the created subfolder.

0
 
LVL 38

Accepted Solution

by:
Geert Gruwez earned 2000 total points
ID: 24412632
ugh ... okay

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);
  item.MakeVisible;
end;
0
 
LVL 1

Author Comment

by:peterkiers
ID: 24412663
Your the best, 500 comming your way.

PK.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

618 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