• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

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.
0
Tom Knowlton
Asked:
Tom Knowlton
1 Solution
 
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
 
Tom KnowltonWeb developerAuthor Commented:
Thanks!
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now