TreeListView and XML-VBForums
Results 1 to 5 of 5

Thread: TreeListView and XML

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2011
    Posts
    192

    TreeListView and XML

    I'm using TreeListView a member of ObjectListView https://www.codeproject.com/Articles...o-Use-ListView

    I need a VB example explain how to use it to show the content of XML file

    Hrere is a sample XML i want to show in TreeListView

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <drives>
    
        <drive name="C:\"><!-- show as root Node -->
            <folder name="some text"><!-- show as child Node -->
                <folder name="some text"><!-- show as child Node -->
                    <file name="some text" date="some text" size="some text"><!-- show 'name' attribute as child Node, show 'date' and 'size' as Column -->
                    <content>some text</content><!-- show in TextBox when parent file selected (I think this is easy for me to do -->
                    </file>
                </folder>
            </folder>
        </drive>
        
        <drive name="D:\"><!-- show as root Node -->
            <folder name="some text"><!-- show as child Node -->
                <folder name="some text"><!-- show as child Node -->
                    <file name="some text" date="some text" size="some text"><!-- show 'name' attribute as child Node, show 'date' and 'size' as Column -->
                    <content>some text</content><!-- show in TextBox when parent file selected (I think this is easy for me to do -->
                    </file>
                </folder>
            </folder>
        </drive>
        
      </drives>
    On Error GoTo Hell

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Dec 2011
    Posts
    192

    Re: TreeListView and XML

    Any help is appreciated!
    On Error GoTo Hell

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    8,947

    Re: TreeListView and XML

    Quote Originally Posted by Absolute_Zero View Post
    Any help is appreciated!
    Here is an example using treeview. To test you will need a form with a button, label, and treeview

    Code:
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim file As XElement '= XElement.Load("path here") 'to load from file
            'file as testdata
            'remove file = if loading from a file
            file = <drives>
                       <drive name="C:\"><!-- show as root Node -->
                           <folder name="folder1"><!-- show as child Node -->
                               <folder name="folder1.1"><!-- show as child Node -->
                                   <file name="file1" date="some text" size="some text"><!-- show 'name' attribute as child Node, show 'date' and 'size' as Column -->
                                       <content>some text1</content><!-- show in TextBox when parent file selected (I think this is easy for me to do -->
                                   </file>
                               </folder>
                           </folder>
                       </drive>
                       <drive name="D:\"><!-- show as root Node -->
                           <folder name="folder2"><!-- show as child Node -->
                               <folder name="folder2.1"><!-- show as child Node -->
                                   <file name="file2" date="some text" size="some text"><!-- show 'name' attribute as child Node, show 'date' and 'size' as Column -->
                                       <content>some text2</content><!-- show in TextBox when parent file selected (I think this is easy for me to do -->
                                   </file>
                               </folder>
                           </folder>
                       </drive>
                   </drives>
    
            BuildTV(file)
    
        End Sub
    
        Private Sub BuildTV(fileXE As XElement)
            TreeView1.Nodes.Clear()
            Dim nd As New TreeNode("Drives")
            TreeView1.Nodes.Add(nd)
            For Each dxe As XElement In fileXE.<drive>
                AddNodes(nd, dxe)
            Next
        End Sub
    
        Private Sub AddNodes(whNode As TreeNode, xe As XElement)
            Dim nd As TreeNode
            If xe.@name <> "" Then
                nd = New TreeNode(xe.@name)
                whNode.Nodes.Add(nd)
                For Each el As XElement In xe.Elements
                    AddNodes(nd, el)
                Next
            ElseIf xe.Name.LocalName = "content" Then
                whNode.Tag = xe.Value 'the tag of the file node will contain the text
            Else
                Stop 'error
            End If
        End Sub
    
        Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterSelect
            If e.Node.Tag IsNot Nothing Then
                Label1.Text = e.Node.Tag.ToString
            Else
                Label1.Text = ""
            End If
        End Sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein
    "They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety." Benjamin Franklin
    "It is not all that I know that is the problem, it is all I think I do that is."

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2011
    Posts
    192

    Re: TreeListView and XML

    Thanks for your answer, unfortunately it is not what i want, i'm talking about ObjectListView (see link in first post), the source code contains an example how to use TreeListView but with file system.

    After some analysis i found that the demo TreeListView uses a class named MyFileSystemInfo to read the file system, what i exactly want is how to make MyFileSystemInfo reads XML file (like the one described above) instead of file system.
    Attached Images Attached Images  
    On Error GoTo Hell

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,350

    Re: TreeListView and XML

    Subscribing... maybe if I get bored later I'll take a crack at it. Can't be all that hard.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.