Avoiding Duplicates in a TTreeView

Sorry I can't award more points.  I don't even have 50 points to give right now.  If you're feeling charitable, please reply.

I am adding several Level 0 siblings to a TTreeView.  I want to avoid adding duplicate Siblings.  For example:

Say this is the list of siblings:

One
Two
Three
Three
Four

The items in the Tree would look like this:

One
Two
Three
Four

The word "Three" would not be duplicated, even though there is more than one in the list I'm reading.

Thanks.
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rwilson032697Commented:
You can do it two ways:

1. Sort the list your are adding to the tree and remove duplicates.

2. Look for each item in the tree before adding it, like this:

Found := false;
for I := 0 to Tree.Items.Count - 1do
  begin
    if tree.items[i].text = TextTextToAdd then
      begin
        Found := True
        break;
      end;
  end;

if not found then
  // add the item to the tree...

3. Set the tree to have its items sorted, add the item then check to see if any of its siblings have the same text. If so delete it.

Cheers,

Raymond.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.