c# - Treeview search results flat list -
how can make list on right populate items meet search criteria? i'm not asking literal code necessarily, general guidance on how so.
i've written code populate list on left c#, supplying directory populate list from. not clear on how list populate correctly when using search field @ top.
should call function researches directory files based on search criteria? or store initial file list in variable , search within populate list?
using system.io; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace directorybrowser { public partial class form1 : form { public form1() { initializecomponent(); listdirectory(treeview1, @"c:\windows"); } public void listdirectory(treeview treeview, string path) { treeview.nodes.clear(); var rootdirectoryinfo = new directoryinfo(path); treeview.nodes.add(createdirectorynode(rootdirectoryinfo)); } public static treenode createdirectorynode(directoryinfo directoryinfo) { var directorynode = new treenode(directoryinfo.name); foreach (var directory in directoryinfo.getdirectories()) { try { directorynode.nodes.add(createdirectorynode(directory)); } catch { // cannot access directory } } foreach (var file in directoryinfo.getfiles()) { directorynode.nodes.add(new treenode(file.name)); } return directorynode; } } }
create parent node should global form. can use parent node without searching directory (folder) on harddisk every time. lets
var directorynode = new treenode(directoryinfo.name);
and add subsequent nodes directorynode code performing this. overall structure added directorynode. add directorynode treeview. treeview populated. when user provides search parameter, search in directorynode not in actual directory, in memory searching fast searching directory on hardisk, , create list of nodes , assign treeview. when search parameter removed user assign directorynode again.
hope suggestion help
Comments
Post a Comment