To peetmce

TeeTree VCL for Borland Delphi and C++ Builder.
Post Reply
tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

To peetmce

Post by tom » Sat Jul 09, 2005 9:26 am

Sorry peet, but i'm unable to contact you by email, I keep getting an error from your server. So I post the answers here:

I'm using D7 and TTree. I want to know how do I change the text font color of the selected item when the selected item is unselected.

Reason:

I want the user to click on an item and then right click to get the popup menu. In the popup menu he has got a few options to update the selected item. What I want to is the font color must change to blue when the Item is was updated. So the user can see all the Items he manually updated.



You can the UnSelectShape event for this:


Code: Select all

procedure TForm1.Tree1UnSelectShape(Sender: TTreeNodeShape);
begin
  Sender.Font.Color :=clBlue;
end;

Next question.


This question is also to do with the popup menu the user has got the following two options.

1. Update selected item only

2. Update Selected Item and Children.


Now my question is, how can I start updating the selected item and all the children of the selected item.

Like

For x :=selected to AllChildren do

Begin

UpdateItem(Selected.Item[x].Tag) //I use the tag to record the primary key of the record

Selected.Item[x].Format.Color :=clBlue; //Change the color of the item to blue to indicate that the item was updated

End;



This can be accomplished as follows:


Code: Select all

procedure TForm1.Children1Click(Sender: TObject);



  procedure IterateChildren(AShape: TTreeNodeShape);
  var i: integer;
  begin
    AShape.Font.Color :=clGreen;
    for i := 0 to AShape.Count-1 do
    begin
      IterateChildren(AShape.Children[i]);
    end;
  end;



begin
  if (Tree1.Selected.Count > 0) then
    IterateChildren(Tree1.Selected.Items[0]);
end;



Here a small example code:


Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, TeeTree, ExtCtrls, TeeProcs, Menus;

type
  TForm1 =3D class(TForm)
    Tree1: TTree;
    TreeNodeShape1: TTreeNodeShape;
    TreeNodeShape2: TTreeNodeShape;
    TreeNodeShape1_TreeNodeShape2: TTreeConnection;
    TreeNodeShape3: TTreeNodeShape;
    TreeNodeShape1_TreeNodeShape3: TTreeConnection;
    TreeNodeShape4: TTreeNodeShape;
    TreeNodeShape1_TreeNodeShape4: TTreeConnection;
    TreeNodeShape5: TTreeNodeShape;
    TreeNodeShape1_TreeNodeShape5: TTreeConnection;
    PopupMenu1: TPopupMenu;
    Edit1: TMenuItem;
    Color1: TMenuItem;
    TreeNodeShape6: TTreeNodeShape;
    TreeNodeShape5_TreeNodeShape6: TTreeConnection;
    TreeNodeShape7: TTreeNodeShape;
    TreeNodeShape5_TreeNodeShape7: TTreeConnection;
    TreeNodeShape8: TTreeNodeShape;
    TreeNodeShape5_TreeNodeShape8: TTreeConnection;
    TreeNodeShape9: TTreeNodeShape;
    TreeNodeShape5_TreeNodeShape9: TTreeConnection;
    Children1: TMenuItem;
    TreeNodeShape10: TTreeNodeShape;
    TreeNodeShape7_TreeNodeShape10: TTreeConnection;
    TreeNodeShape11: TTreeNodeShape;
    TreeNodeShape7_TreeNodeShape11: TTreeConnection;
    procedure Tree1UnSelectShape(Sender: TTreeNodeShape);
    procedure Color1Click(Sender: TObject);
    procedure Edit1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Children1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses TreeShEd;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Tree1.SingleSelection :=true;
end;

procedure TForm1.Tree1UnSelectShape(Sender: TTreeNodeShape);
begin
  Sender.Font.Color :=clBlue;
end;

procedure TForm1.Color1Click(Sender: TObject);
begin
  if (Tree1.Selected.Count > 0) then
    Tree1.Selected.Items[0].Font.Style := Tree1.Selected.Items[0].Font.Style + [fsBold];
end;

procedure TForm1.Edit1Click(Sender: TObject);
begin
  if (Tree1.Selected.Count > 0) then
    EditTreeShape(self, Tree1.Selected.Items[0]);
end;

procedure TForm1.Children1Click(Sender: TObject);

  procedure IterateChildren(AShape: TTreeNodeShape);
  var i: integer;
  begin
    AShape.Font.Color :=clGreen;
    for i := 0 to AShape.Count-1 do
    begin
      IterateChildren(AShape.Children[i]);
    end;
  end;

begin
  if (Tree1.Selected.Count > 0) then
    IterateChildren(Tree1.Selected.Items[0]);
end;

end.

Post Reply