I realized after you commented below that I had said two different
things.  The node captions can be the same on the same levels provided they
are not under the same parent.  So if you had a root node of "One" with
three child nodes of "A", "B", and "C", all three could have a child at the
same level with the caption of "D", but there couldn't be two child nodes
directly under any of them with the same caption, nor can any child caption
be the same as its immediate parent.  I think I've explained that correctly
this time! <g>  Knowing the parent caption is easy, and I think the
parent.items property should do the trick for getting the caption of all
it's immediate children.  Thanx.

from Robert Meek dba Tangentals Design  CCopyright 2006
Proud to be a moderator of "The Delphi Lists" at elists.org

"When I examine myself and my methods of thought, I come to the conclusion
that the gift of Fantasy has meant more to me then my talent for absorbing
positive knowledge!"
                                                    Albert Einstein


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Rob Kennedy
Sent: Tuesday, June 13, 2006 10:46 PM
To: Borland's Delphi Discussion List
Subject: Re: Checking for duplicates in a treeview

Robert Meek wrote:
> I'm looking for the most efficient way to ensure the user hasn't
> entered to add or edit a node in a treeview component a name already being
> used by another node in the same level.  Basically there is a non-editable
> root node under which the user can add as many child nodes as wanted, and
> under each child node as many children and so on.  So whatever level the
> user has selected when adding or editing I have to prevent them from
> entering a name equal to any other with the same parent.  I've tried a
> couple things but my experience with treeviews isn't a lot and I know
there
> must be an easy way to handle this.

In the OnEdited event, you're given the new text of the node, presumably 
before it's been assigned to the node's caption. In that event, compare 
that string with the captions of the other nodes. If you find a match, 
then set the string parameter's value back to the node's original caption.

First you said you want to consider all the nodes at the same level. 
That includes not just siblings, but also cousins. Later you said you 
want nodes with the same parent. Selecting a group of siblings is easy 
-- read the TTreeNode.Parent.Items property. Selecting everything at the 
same level may be harder. The TTreeNode.Level property might help.

-- 
Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to