|
Prev: Using Replace function in DataTable.Select
Next: Enable (show) and Disable (hide) ConfirmButtonExtender
From: Brian Nicholson on 3 Jul 2008 14:37 Hello, I've created a treeview control that gives a folder browser view of a given computer. The treeview is populated using the following methods: Protected Sub treeDst_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles treeDst.Init Dim dirInfo As New DirectoryInfo("C:\") dstDir.Text = dirInfo.FullName For Each dir As DirectoryInfo In dirInfo.GetDirectories() Dim node As TreeNode = New TreeNode(dir.Name, dir.FullName) node.Expanded = False node.PopulateOnDemand = True CType(sender, TreeView).Nodes.Add(node) Next End Sub Protected Sub PopulateNode(ByVal sender As Object, ByVal e As TreeNodeEventArgs) Handles treeSrc.TreeNodePopulate, treeDst.TreeNodePopulate On Error Resume Next Dim dirInfo As New DirectoryInfo(e.Node.Value) For Each dir As DirectoryInfo In dirInfo.GetDirectories() Dim node As TreeNode = New TreeNode(dir.Name, dir.FullName) node.Expanded = False node.PopulateOnDemand = True e.Node.ChildNodes.Add(node) Next End Sub What I'd like to be able to be able to do is figure out a (clean) way to filter out the directories before adding them as nodes to the treeview. For example, a few things I'd like to do is prevent some specified directories from showing up entirely, or allow the user to only go a certain depth in some specified directory. I realize I could code all of this logic directly in the PopulateNode class, but I don't feel like it's very clean to hard code a bunch of strings into my script. I was thinking I might somehow be able to utilize an XML file, but I don't know how. Something along these lines, perhaps: <root> <dir name="folder1" hidden="true" /> <dir name="folder2" maxDepth="3" /> <dir name="folder3"> <dir name="subFolder1" maxDepth="1" /> <dir name="subFolder2" hidden="true" /> </dir> </root> Would the best thing to do be to have some kind of filter method that goes through the XML file and looks for the node to be added before adding it to the treeview? Or am I taking the wrong approach to this? Thank you for your time. |