3 Replies Latest reply on Apr 9, 2009 10:22 AM by Flex harUI

    How do you sort a Flex tree and keep your selected item?


      I am experiencing issues when I sort a Flex tree. Let's say I have two items in a tree, item B and item C. Assume when the tree renders for the first time that the items are in the following order: B, C. Now if I rename C to A and then sort the tree (assuming order is now A,B), I can not select B because the tree still thinks that B is selected even though A has the blue highlight over it. I can however select A again. I have tried looping over the tree items and manually setting the selected index, but this does not work. If I set the selectedItem property to null, then nothing is selected and I can't get the blue highlight to show up again by setting the selectedIndex property. What is going on here? I am using Flex 3.2. This sounds like a bug to me. If the tree is smart enough to update the display when the bounded collection is sorted, it should be smart enough to update the selected item correctly.


      I am sorting the nodes in the tree by sorting the data provider, which is an ArrayCollection.


      var sort:Sort = new Sort();
      sort.fields = [new SortField("CapitalLetter", true)];

      capitalLettersDataProvider.sort = sort;