Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to ensure that every node in a TTreeView is unique Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
31-Oct-02
Category
VCL-General
Language
Delphi 2.x
Views
71
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I want to make sure that every node in my TreeView is unique - like making a new 
folder in Windows Explorer.

Answer:

It is a timing issue, it looks like you cannot set the node back to edit mode in 
the onEdited event. So post a user message to the form and set the node to edit 
mode in the handler for this message:

1   unit Unit1;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7     StdCtrls, ComCtrls;
8   
9   const
10    UM_EDITNODE = WM_USER;
11  type
12    TUmEditNode = record
13      msg: Cardinal;
14      node: TTreenode;
15      unused: Longint;
16      result: Longint;
17    end;
18  
19    TForm1 = class(TForm)
20      Edit1: TEdit;
21      Edit2: TEdit;
22      TreeView1: TTreeView;
23      procedure TreeView1Edited(Sender: TObject; Node: TTreeNode; var S: string);
24    private
25      { Private declarations }
26      procedure UMEditNode(var msg: TUMeditNode); message UM_EDITNODE;
27    public
28      { Public declarations }
29    end;
30  
31  var
32    Form1: TForm1;
33  
34  implementation
35  
36  {$R *.DFM}
37  
38  procedure TForm1.TreeView1Edited(Sender: TObject; Node: TTreeNode; var S: string);
39  var
40    n: TTreenode;
41  begin
42    n := (Sender as TTreeview).Items[0];
43    while n <> nil do
44    begin
45      if n <> Node then
46      begin
47        if AnsiCompareText(n.Text, S) = 0 then
48        begin
49          ShowMessage('Item already exists, use different text');
50          S := node.text;
51          PostMessage(handle, UM_EDITNODE, integer(node), 0);
52          break;
53        end;
54      end;
55      n := n.GetNext;
56    end;
57  end;
58  
59  procedure TForm1.UMEditNode(var msg: TUMeditNode);
60  begin
61    if assigned(msg.node) then
62      msg.node.edittext;
63  end;
64  
65  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC