Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Add items to 3 separate listview colums when readuing through xml nodes

Posted on 2014-02-24
10
Medium Priority
?
215 Views
Last Modified: 2014-02-25
Any idea how I get the three separate data pieces into their own column on a listview? They all end up in the very first column.

        For Each sPath As String In IO.Directory.GetFiles(TextBox1.Text)
            TextBox2.Text = sPath
            If IO.Path.GetExtension(sPath) = ".xml" Then

                Dim doc As New XmlDocument()
                Dim nodes As XmlNodeList
                doc.Load(sPath)

                nodes = doc.SelectNodes("/log/entry")
                Dim node As XmlNode

                For Each node In nodes

                        Dim nodecliconnaddr As XmlNode = node.SelectSingleNode("cliconnaddr")
                    If nodecliconnaddr IsNot Nothing Then
                        ListView1.Columns(0).ListView.Items.Add(nodecliconnaddr.InnerText)
                        'ListBox1.Items.Add(nodecliconnaddr.InnerText)
                    End If

                            Dim nodecmd As XmlNode = node.SelectSingleNode("cmd")
                    If nodecmd IsNot Nothing Then
                        ListView1.Columns(1).ListView.Items.Add(nodecmd.InnerText)
                        'ListBox2.Items.Add(nodecmd.InnerText)
                    End If

                            Dim nodelog_time As XmlNode = node.SelectSingleNode("log_time")
                    If nodelog_time IsNot Nothing Then
                        ListView1.Columns(2).ListView.Items.Add(nodelog_time.InnerText)
                        '   ListBox3.Items.Add(nodelog_time.InnerText)
                    End If

                Next
            End If

Open in new window

0
Comment
Question by:MarcViste
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39883930
Change line 16 to

ListView1.Columns(0).SubitemsItems.Add(nodecliconnaddr.InnerText)

Line 22 to

ListView1.Columns(0).SubItems.Add(nodecmd.InnerText)

Line 28 to

ListView1.Columns(0).SubItems.Add(nodelog_time.InnerText)



*Untested code
0
 

Author Comment

by:MarcViste
ID: 39883950
I get the following error for all three lines the first one had items twice as well but I sqaw and fixed that right away)

'Subitems' is not a member of 'system.windows.forms.ColumnHeader'
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39884044
Ah sorry try

ListView1.Items(0).SubitemsItems.Add(nodecliconnaddr.InnerText)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:MarcViste
ID: 39884059
at least the command is on the right track, when I run it I get the following:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll

Additional information: InvalidArgument=Value of '0' is not valid for 'index'.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39884082
Try 1
0
 

Author Comment

by:MarcViste
ID: 39884096
tried 1, 2, 3     ...
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39885359
I got around to testing the code.

Here is your updated code


        For Each sPath As String In IO.Directory.GetFiles(TextBox1.Text)
            TextBox2.Text = sPath
            If IO.Path.GetExtension(sPath) = ".xml" Then

                Dim doc As New XmlDocument()
                Dim nodes As XmlNodeList
                doc.Load(sPath)

                nodes = doc.SelectNodes("/log/entry")
                Dim node As XmlNode

                For Each node In nodes
                        Dim item As New ListViewItem("Text in first column")
                        Dim nodecliconnaddr As XmlNode = node.SelectSingleNode("cliconnaddr")
                    If nodecliconnaddr IsNot Nothing Then
                        item.SubItems.Add(nodecliconnaddr.InnerText)
                    End If

                            Dim nodecmd As XmlNode = node.SelectSingleNode("cmd")
                    If nodecmd IsNot Nothing Then
                        item.SubItems.Add(nodecmd.InnerText)
                    End If

                            Dim nodelog_time As XmlNode = node.SelectSingleNode("log_time")
                    If nodelog_time IsNot Nothing Then
                        item.SubItems.Add(nodelog_time.InnerText)
                    End If
                    ListView1.Items.Add(item)
                Next
            End If

Open in new window

0
 

Author Comment

by:MarcViste
ID: 39885598
So this code displays "Text in first column" in the first column and then adds the ccliconnaddr.inner text properly in the second, and then lumps the 2nd and 3rd info fields together in the third column.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 39885720
Try following then


        For Each sPath As String In IO.Directory.GetFiles(TextBox1.Text)
            TextBox2.Text = sPath
            If IO.Path.GetExtension(sPath) = ".xml" Then

                Dim doc As New XmlDocument()
                Dim nodes As XmlNodeList
                doc.Load(sPath)

                nodes = doc.SelectNodes("/log/entry")
                Dim node As XmlNode

                For Each node In nodes
                        Dim item As New ListViewItem("Text in first column")
                        Dim nodecliconnaddr As XmlNode = node.SelectSingleNode("cliconnaddr")
                    If nodecliconnaddr IsNot Nothing Then
                        item.Text = (nodecliconnaddr.InnerText)
                    End If

                            Dim nodecmd As XmlNode = node.SelectSingleNode("cmd")
                    If nodecmd IsNot Nothing Then
                        item.SubItems.Add(nodecmd.InnerText)
                    End If

                            Dim nodelog_time As XmlNode = node.SelectSingleNode("log_time")
                    If nodelog_time IsNot Nothing Then
                        item.SubItems.Add(nodelog_time.InnerText)
                    End If
                    ListView1.Items.Add(item)
                Next
            End If

Open in new window

0
 

Author Closing Comment

by:MarcViste
ID: 39885731
Still some tiny bugs to work out, but this got me on the right track! Thank you!
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Starting up a Project

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question