views:

305

answers:

2

I am developing an app ( A database file system ). I am using WPF treeview in its GUI.The treeview items are directly extracted from my apps database.

I want to search and highlight the treeview items as I type. To understand the question better, consider the keyword search results shown in browsers.


alt text

How do I achieve that in my context?

+1  A: 

You can do this with a combination of the "KeyDown" event on whatever control the user types into.

And this ......

Highlight whole treeview lines

DrLazer
+1  A: 

Use a view model, wrap all the items that appear in your tree view. Give them all a IsHighlighted property. Perform your search on the view model items, if they match the criterion, set your IsHighlighted property to true. Use a trigger on your treeviewitem style that is bound to the IsHighlighted property, that updates the colour of the background.

The treeview can only have one selected item at once (it does not support multiple selection like the list view) So if you want to have more than one search result, setting the SelectedItem of the treeview wont be enough. Using a view model which has properties such as IsExpanded can also allow you to do some funky stuff. e.g. if a node is 'found' you can expand all the other nodes above it to make it visible.

Aran Mulholland