Filtering data in TreeView

Discussion in 'ASP .Net' started by Brian Nicholson, Jul 3, 2008.

  1. 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.
     
    Brian Nicholson, Jul 3, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. New User
    Replies:
    1
    Views:
    464
    Saravana [MVP]
    Nov 27, 2003
  2. =?Utf-8?B?UGF1bG8=?=

    Re: Filtering data in a Datagrid

    =?Utf-8?B?UGF1bG8=?=, Apr 1, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,585
    William Ryan eMVP
    Apr 1, 2004
  3. JUAN ERNESTO FLORES BELTRAN

    Advanced Treeview Filtering Help

    JUAN ERNESTO FLORES BELTRAN, Apr 27, 2006, in forum: Python
    Replies:
    2
    Views:
    404
    alisonken1
    Apr 28, 2006
  4. JUAN ERNESTO FLORES BELTRAN

    fwd: Advanced Treeview Filtering Help

    JUAN ERNESTO FLORES BELTRAN, Apr 27, 2006, in forum: Python
    Replies:
    0
    Views:
    282
    JUAN ERNESTO FLORES BELTRAN
    Apr 27, 2006
  5. Guest
    Replies:
    5
    Views:
    442
    Scott David Daniels
    Mar 30, 2007
Loading...

Share This Page