Update 26/09/2011 – There is an issue with the control where the entire tree is loaded, which may affect performance and memory allocation when working with many items. Unfortunately, I don’t think I would be able to fix that any time soon.
A few years back, I built a WPF control that I decided to share here now.
The control is called ComboView – A ComboBox showing a TreeView inside to display hierarchical data (you can use it for flat data if you need its features though).
The control provides some really nice built-in features that you can use.
The control uses another control that I had to write, called ‘ExtendedTreeView’. This control inherits from TreeView and adds some features on top of that.
Another thing, I used the ‘Reveal’ control provided by Bag’o’Tricks, it has some very cool stuff, worth a look.
Following is a common mode that you can use it for –
In order to see all the options and features, feel free to download the code with the showcases here – Zuker.WpfSamples.zip
- If you wish to bind to the SelectedViewItems or SelectedViewValues (Supports Two-Way), the source property must be of type ‘ObservableCollection<object>’
- If you wish to use SelectedViewValue / SelectedViewValues, you should set SyncSelectedViewValues to true.
- If you set selection in code – items or values, the SelectedViewItems property of the ComboView will not necessarily include these items right away.
- This is because of the true nature of WPF’s TreeView, I may have to expand the items internally
- If you’re dependent on that in the next line, put this logic in Dispatcher.BeginInvoke, it should be ready there.
- Since there were some patches along the way, and features that were added at a later stage, the code can be organized better