Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering a Treeview

Status
Not open for further replies.

Orion45

IS-IT--Management
Feb 6, 2002
155
US
I am trying to build a menu in .net using a treeview control populated by an XML file. This XML is divided into several sections since the same xml is used throughout the application. It is indexed by Area, Application, and Page. I need a way to filter the treeview to only display nodes that are specific to the page I am currently on. I am new to .net and do not know the syntax for doing this. My code currently displays everything in the xml file. Any advice on this is appreciated. Thanks,
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim dom As New XmlDocument()
            dom.Load(TextBox1.Text)

            TreeView1.Nodes.Clear()
            TreeView1.Nodes.Add(New TreeNode(dom.DocumentElement.Name))
            Dim tNode As New TreeNode()
            tNode = TreeView1.Nodes(0)

            AddNode(dom.DocumentElement, tNode)
            TreeView1.ExpandAll()
        Catch xmlEx As XmlException
            MessageBox.Show(xmlEx.Message)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub AddNode(ByRef inXmlNode As XmlNode, ByRef inTreeNode As TreeNode)
        Dim xNode As XmlNode
        Dim tNode As TreeNode
        Dim Parent As XmlNode
        Dim nodeList As XmlNodeList
        Dim i As Long

        If inXmlNode.HasChildNodes() Then
            nodeList = inXmlNode.ChildNodes
            For i = 0 To nodeList.Count - 1
                xNode = inXmlNode.ChildNodes(i)
                inTreeNode.Nodes.Add(New TreeNode(xNode.Name))
                tNode = inTreeNode.Nodes(i)
                AddNode(xNode, tNode)
            Next
        Else
            inTreeNode.Text = (inXmlNode.OuterXml).Trim
        End If
    End Sub
 
>> filter the treeview to only display nodes that are
>> specific to the [red]page[/red] I am currently on.

What are you referring to by "page"?

-pete
 
Sorry about the confusion there. My .xml file is separated into sections for area, application, and page. I only want to display nodes that contain the title and description and are specific to a given page tag. Below is an excerpt from my XML file.
Code:
<area id=&quot;WebApplicationPortal&quot;>
		<application id=&quot;Pable&quot; xmlns:msxsl=&quot;urn:schemas-microsoft-com:xslt&quot;>
			<page id=&quot;manacc&quot;>
				<title>Managing Your Account</title>
				<order>09</order>
				<item id=&quot;MAProxyIDs&quot;>
					<title>Proxy IDs</title>
					<order>03</order>
					<summary>Description of Proxy IDs and their function.</summary>
					<text>Proxy IDs allow an attorney to give access permissions to another user.  The permissions can be revoked as needed and if necessary the ID can be changed all together. etc....</text>
				</item>
				<item id=&quot;manacc&quot;>
					<title>Mobile Account Requirements</title>
					<order>05</order>
					<summary></summary>
					<text>Some portal applications may offer mobile communications accessibility...</text>
				</item>
				<item id=&quot;manman&quot;>
					<title>Manage Account Page</title>
					<order>01</order>
					<summary></summary>
					<text>The Manage Account page displays the following fields:</text>
				</item>
			</page>
			<page id=&quot;sitnav&quot;>
Thanks a lot for your help!
 
I have no idea what your trying to do but to query a DOM document for the page element in your post you use a XPath query //page[@id='manacc']

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top