delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
498 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


inline-editing with a TTreeViewFormat this article printer-friendly!Bookmark function is only available for registered users!
editing text in nodes - advanced way
Product:
Delphi all versions
Category:
VCL-General
Skill Level:
Scoring:
Last Update:
07/02/2003
Search Keys:
delphi delphi3000 article borland vcl code-snippet treeview nodes
Times Scored:
2
Visits:
2319
Uploader: Omer Can
Company:
Reference: N/A
 
Question/Problem/Abstract:
how to do inline-editing with a ttreeview
Answer:



It is much easier than you might think.

I give you the code, the dfm and the dpr....

  Omer Yasar Can omercan@home.nl

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ExtCtrls, StdCtrls, Menus;


type
  TForm1 = class(TForm)
    Panel1: TPanel;
    TreeView1: TTreeView;
    StatusBar1: TStatusBar;
    Edit1: TEdit;
    procedure TreeView1Editing(Sender: TObject; Node: TTreeNode;
      var AllowEdit: Boolean);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
   Treeview1.FullExpand; //optional
end;

{------------------------------------------------------------------------------}

procedure TForm1.TreeView1Editing(Sender: TObject; Node: TTreeNode;
  var AllowEdit: Boolean);
var
  NodeRect:TRect;
begin
  with Node do begin
     NodeRect:=DisplayRect(True);
     Edit1.Top := NodeRect.Top; Edit1.Left := NodeRect.Left;
     Edit1.text := Text;
     Edit1.Visible := true;
     Edit1.SetFocus;
   end;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if NOT ( key in [ 'A'..'Z', 'a'..'z', '0'..'9', ' ', chr(13), #8 ] )
    //here's the advantage: you define what the user should enter!
    then key := #0
    else if key = chr(13) then begin
      TreeView1.Selected.Text := Edit1.Text;
      Edit1.visible := false;
      TreeView1.SetFocus; //optional
    end;
end;

end.


the dfm-file:

object Form1: TForm1
  Left = 468
  Top = 363
  Width = 244
  Height = 161
  Caption = 'Exampe fuo TTreeView'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 236
    Height = 115
    Align = alClient
    BevelInner = bvLowered
    Caption = 'Panel1'
    TabOrder = 0
    object TreeView1: TTreeView
      Left = 2
      Top = 2
      Width = 232
      Height = 111
      Align = alClient
      Indent = 19
      TabOrder = 0
      OnEditing = TreeView1Editing
      Items.Data = {
        02000000270000000000000000000000FFFFFFFFFFFFFFFF0000000002000000
        0E496E6C696E652065646974696E671F0000000000000000000000FFFFFFFFFF
        FFFFFF000000000000000006537562315F611F0000000000000000000000FFFF
        FFFFFFFFFFFF000000000000000006537562315F621E00000000000000000000
        00FFFFFFFFFFFFFFFF000000000200000005526F6F74321F0000000000000000
        000000FFFFFFFFFFFFFFFF000000000000000006537562325F611F0000000000
        000000000000FFFFFFFFFFFFFFFF000000000000000006537562325F62}
    end
    object Edit1: TEdit
      Left = 96
      Top = 24
      Width = 65
      Height = 21
      Color = clYellow
      TabOrder = 1
      Text = 'Edit1'
      Visible = False
      OnKeyPress = Edit1KeyPress
    end
  end
  object StatusBar1: TStatusBar
    Left = 0
    Top = 115
    Width = 236
    Height = 19
    Panels = <
      item
        Text = 'Dir:\TreeView_InlineEditing'
        Width = 50
      end>
    SimplePanel = False
  end
end

the dpr-file:

program TreeView_InlineEditing;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
D. Wischnewski
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)