Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Filtering data in TreeView

Reply
Thread Tools

Filtering data in TreeView

 
 
Brian Nicholson
Guest
Posts: n/a
 
      07-03-2008
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to access the Page from a TreeNode (treeview 's element) : addinga context menu to a treeview abargaddon ASP .Net Building Controls 0 01-17-2008 11:05 AM
Creating a new data structure while filtering its data origin. Python 5 03-30-2007 02:37 AM
Advanced Treeview Filtering Help JUAN ERNESTO FLORES BELTRAN Python 2 04-28-2006 12:09 AM
fwd: Advanced Treeview Filtering Help JUAN ERNESTO FLORES BELTRAN Python 0 04-27-2006 06:48 PM
ASP.NET 2.0 TreeView - Programatically Selecting A TreeView Node =?Utf-8?B?VHltYm93?= ASP .Net 2 01-10-2006 03:51 AM



Advertisments