13

we're trying to come up with a good way to virtualize the TreeView, the data is not really a problem because it's very light (around 16 bytes per item), the problem is that we could potentially have tens of thousands, and although the actual data would only take 160 kb of memory, the treeview items do use a lot more memory. We've tried virtualization with 3 different trees now, WPF, Infragistics and Telerik. All of them have big issues that makes them unusable for our application:

WPF TreeView: The scroll bar shows some weird behavior, jumps around a lot, changes size inconsistently, scrolling by dragging it with the mouse doesn't work properly (jumps back and forth)

Telerik: Items disappear, scroll bar is erratic too, items randomly expand collapse, styles don't work

Infragistics: Items are not virtualized at all, every item remains in memory making virtualization useless.

We've been struggling with this a couple of months now, and we haven't been able to find a good solution. Has any of you successfully implemented virtualization in a TreeView with more than 9000 items? If so, what was your strategy? Did you use third party controls? Did it work 100%?

Any suggestion extremely appreciated.

Thanks.

akjoshi
  • 15,374
  • 13
  • 103
  • 121
Carlo
  • 25,602
  • 32
  • 128
  • 176
  • 1
    +1 I have the same problem with the WPF Virtualized Treeview, tried everything and the behavior is still erratic when scrolling is involved. – BrokenGlass Jan 05 '11 at 01:29
  • @BrokenGlass Thanks for supporting the question. I hope we get a good solution for this. – Carlo Jan 05 '11 at 01:50
  • also see my related question here (obviously w/o answer): http://stackoverflow.com/questions/4074475/scrolling-bug-in-wpf-virtualized-treeview – BrokenGlass Jan 05 '11 at 01:53

2 Answers2

5

We've used Bea Costa's Stollnitz's trick of indenting items in a ListView and using UI Virtualization to good effect.

http://www.beacosta.com/blog/?p=45

I've gotten 100,000 items in the backing ICollectionView, and it is still quite responsive to filtering, etc.

akjoshi
  • 15,374
  • 13
  • 103
  • 121
codekaizen
  • 26,990
  • 7
  • 84
  • 140
  • it's sad that this doesn't work out of the box with virtualized Treeviews, instead having to use these kinds of tricks – BrokenGlass Jan 05 '11 at 19:17
  • But she mentions that this solution was because the TreeView did not have virtualization pre 3.5, so it makes me wonder if it really does solve the problem. I'll give it a shot right away, thanks for the suggestion. – Carlo Jan 05 '11 at 22:39
  • I was using UI virtualization with TreeView running v4.0, and it still was not very well performing. It turned out that the reason was it is easy to break virtualization using the TreeView. The ListView allows you to get around these limitations. – codekaizen Jan 05 '11 at 22:54
  • Does your data hierarchy has more than 2 levels? If so, is each level a different type? I can't get it to work with my data, I have 4 levels, each level is a different type containing a list of the next one. Type1 contains a list of Type2, Type2 a list of Type3 and Type3 a list of Type4. – Carlo Jan 06 '11 at 00:20
  • Yeah, I just figured it out, I wanted to still use a HierachicalDataTemplate to bind the 'tree', but I realized it's actually one big list that indents itself based on the level, and not on the hierarchy. Interesting. Thanks for the suggestion I'll keep working on it. – Carlo Jan 06 '11 at 00:59
  • We'll go with this approach. I did some prototype code to make it work with our data hierarchy and so far, so good. Thanks for the suggestion. – Carlo Jan 07 '11 at 19:04
2

We are also in a similar situation, we tried using Syncfusion tree-view and it was pathetic. As we didn't had the choice of any other 3'rd party control and no better solution was available, We finally settled with Virtualization and Load on demand(Lazy loading) together.

As in our case, generally all nodes won't be expanded at any given time. This solves the scrolling issues to some extent and makes the application usable in most of the scenarios. Although we still have our figures crossed and keep looking for a better solution.

I would like to mention here that using both Virtualization and Load on demand(Lazy loading) together have its own side effects -

Need a sample for WPF TreeView search with Virtualization and Load On Demand

.

Some samples for implementing Load on demand -

http://www.codeproject.com/KB/WPF/WPF_Explorer_Tree.aspx

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/1eb3ed3d-6379-4353-9f35-2c0aecb885f2/

http://www.telerik.com/help/wpf/radtreeview-features-load-on-demand.html

Community
  • 1
  • 1
akjoshi
  • 15,374
  • 13
  • 103
  • 121
  • I did try to combine virtualization and load on demand, but unfortunately, virtualization doesn't work when you create the items on the fly, only when binding (on the WPF and Telerik's TreeViews at least), so we had to steer away from that option too. We could potentially have thousands of items expanded, which means thousands of TreeViewItems in memory. Thanks for the suggestion. – Carlo Jan 05 '11 at 22:36