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

Reply via email to