I have a TreeView in my a C# winform. I would like to be able to add a search functionality through a search box. Basically as the user types in letters (I\'m guessing on th
Every node in TreeView
has Expanded
and IsVisible
properties. The number of items which are visible at the same time is limited (TreeView.VisibleCount
). Based on this information you can reduce the number of nodes to probe dramatically.
When scanning the node and it's child nodes you can abort recursion as you find the first match inside collapsed node, thus you already know it has at least one child and will be visible anyway.
Perform filtering asynchronously. (use new Task()
for instance) Start the first task after minimal number of chars was typed (let's say 3). Every next typed char must cancel the running task and start the new one.