2 Replies Latest reply on Sep 14, 2008 1:14 AM by LuckyNumberSleven

    Tree control erroneously displays nodes multiple times

    rmeador Level 1
      I'm attempting to use a Tree control to display some data. I'm using an HierarchicalCollectionView as the dataProvider. All the data displays, but it appears on the wrong level. For instance, on the root level, it displays the root node (correctly marked with the folder icon as having children), plus all the children (on the root level!) If I expand the root node, underneath it it displays its children as expected -- now there are 2 copys of all the children, one in the correct place and one at the root level. If I expand 2nd-level nodes, their children (and children's children, etc) display underneath them... the pattern continues. It looks like every level of the hierarchy displays ALL the nodes underneath it, no matter how many levels down.

      I think I know why this happens: a HierarchicalCollectionView's createCursor() function returns an IViewCursor that treats the collection as linear instead of hierarchical. The Tree then uses this cursor to visit every node in the tree, displaying it. When expanding a node, it again uses one of these linear-type cursors, but on the children of the node clicked on, so it displays all the children underneath it and their children, etc. This seems like a major bug in the library -- I'm pretty sure this isn't a problem with my code. Doesn't it seem natural to use a HierarchicalCollectionView with a Tree control? Has no one else ever experienced this issue? I'd expect it to work, especially since HierarchicalCollectionView extends ICollectionView, which is what the dataProvider wants. I've looked through the source of the Tree class (and List, and ListBase) and I think it all boils down to not using the dataDescriptor's getChildren() method and instead using createCursor() directly on the dataProvider. The dataDescriptor's getChildren() method returns an ICollectionView that correctly only contains the next-level nodes, not all of the ones all the way to the bottom of the hierarchy. I think the bad behavior is inherited from ListBase (and in that class, it actually makes sense... too bad nobody overrode it in Tree).

      Am I wrong? Am I making a mistake somewhere in my code? If not, is there a workaround? Has a bug report been filed, and should I file one if this is indeed a bug? Any help or insight would be greatly appreciated.
        • 1. Re: Tree control erroneously displays nodes multiple times
          rmeador Level 1
          OK, after banging my head against this for a day and a half, I finally have an answer. It seems that the problem is my root node (and possibly others; I didn't delve that deep) is "open". I guess something, somewhere is calling IHierarchicalCollectionView.openNode() on it. Closing the node(s) makes the problem disappear. I've attached a reproduction script that's about as simple as I can make it (I guess it could be simpler with less data, but oh well). Why does this happen? Should I open a bug report? It seems to me that the correct behavior would be to have the open node(s) disclosure controls start out open rather than incorrectly displaying their children as on the same level as them.
          • 2. Re: Tree control erroneously displays nodes multiple times
            LuckyNumberSleven Level 1
            Sounds like a conflict with view.openNode(mydata);

            I wonder why?