RoyLittle0
Active member
How can i add data to a listview from a xml file, i want to add two columns to the list view, i can add data to a listbox but i cant seem to do the same to a listview, the data i need to add is from a xml file, which is "id" and "Name" in two separate columns, they are part of a cascading set of 12 listview boxes each dependent on the one above and i need the id to implement the next cascade.
There are 12 list views in total, so i assume i need to define what goes into each of the columns, can this be done globally for all listviews?
The below code has been modified for listboxes to give me the additional column but i cant seem to get it to work in listview
any pointers would be appreciated
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
	
		
			
		
		
	
				
			There are 12 list views in total, so i assume i need to define what goes into each of the columns, can this be done globally for all listviews?
The below code has been modified for listboxes to give me the additional column but i cant seem to get it to work in listview
any pointers would be appreciated
			
				VB.NET:
			
		
		
		    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListBoxes.AddRange({Solution1, Solution2, Solution3, Solution4, Solution5, Solution6, Solution7, Solution8, Solution9, Solution10, Solution11, Solution12}) 'this has to be done here to ensure that the controls have initialised
        doc = XDocument.Load(IO.Path.Combine(Application.StartupPath, "Test.xml"))
        ' This will fill solution box 1 with the Root 1 information from the xml file
        Dim Root As New ListViewItem
            (
        From A In doc...<Section1>
        Select Section1 = A.@id()
            ).ToArray
        Solution1.Items.Add(Root)
    End Sub
    Private Sub Sloution1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Select Case ListBoxes.IndexOf(sender)
            'Solution1.click event, fills Solution box 2 with values based on the information in Solution box 1
            Case 0
                Dim Root2 =
                (
                    From a In doc...<Section1>
                    Where a.@id = Solution1.Text
                    From b In a.<Root2>.<Section2>
                    Select b.@id
                ).ToArray
                Solution2.Items.Add(Root2)
                'Solution2.click event, fills Solution box 3 with values based on the information in Solution box 2
            Case 1
                If Solution2.Items.Count > 0 Then
                    Dim Root3 =
                    (
                    From b In doc...<Section2>
                    Where b.@id = (Solution2.Text)
                    From c In b.<Root3>.<Section3>
                    Select c.@id
                    ).ToArray
                    Solution3.Items.Add(Root3)
                End If
                'Solution3.click event, fills Solution box 4 with values based on the information in Solution box 3
            Case 2
                If Solution3.Items.Count > 0 Then
                    Dim Root4 =
                    (
                    From c In doc...<Section3>
                    Where c.@id = Solution3.Text
                    From d In c.<Root4>.<Section4>
                    Select d.@id
                    ).ToArray
                    Solution4.Items.Add(Root4)
                End If
                'Solution4.click event, fills Solution box 5 with values based on the information in Solution box 4
            Case 3
                If Solution4.Items.Count > 0 Then
                    Dim Root5 =
                    (
                    From d In doc...<Section4>
                    Where d.@id = Solution4.Text
                    From f In d.<Root5>.<Section5>
                    Select f.@id
                    ).ToArray
                    Solution5.Items.Add(Root5)
                End If
                'Solution5.click event, fills Solution box 6 with values based on the information in Solution box 5
            Case 4
                If Solution5.Items.Count > 0 Then
                    Dim Root6 =
                    (
                    From f In doc...<Section5>
                    Where f.@id = Solution5.Text
                    From g In f.<Root6>.<Section6>
                    Select g.@id
                    ).ToArray
                    Solution6.Items.Add(Root6)
                End If
                'Solution6.click event, fills Solution box 7 with values based on the information in Solution box 6
            Case 5
                If Solution6.Items.Count > 0 Then
                    Dim Root7 =
                    (
                    From g In doc...<Section6>
                    Where g.@id = Solution6.Text
                    From h In g.<Root7>.<Section7>
                    Select h.@id
                    ).ToArray
                    Solution7.Items.Add(Root7)
                End If
                'Solution7.click event, fills Solution box 8 with values based on the information in Solution box 7
            Case 6
                If Solution7.Items.Count > 0 Then
                    Dim Root8 =
                    (
                    From h In doc...<Section7>
                    Where h.@id = Solution7.Text
                    From i In h.<Root8>.<Section8>
                    Select i.@id
                    ).ToArray
                    Solution8.Items.Add(Root8)
                End If
                'Solution8.click event, fills Solution box 9 with values based on the information in Solution box 8
            Case 7
                If Solution8.Items.Count > 0 Then
                    Dim Root9 =
                    (
                    From i In doc...<Section8>
                    Where i.@id = Solution8.Text
                    From j In i.<Root9>.<Section9>
                    Select j.@id
                    ).ToArray
                    Solution9.Items.Add(Root9)
                End If
                'Solution9.click event, fills Solution box 10 with values based on the information in Solution box 9
            Case 8
                If Solution9.Items.Count > 0 Then
                    Dim Root10 =
                    (
                    From j In doc...<Section9>
                    Where j.@id = Solution9.Text
                    From k In j.<Root10>.<Section10>
                    Select k.@id
                    ).ToArray
                    Solution10.Items.Add(Root10)
                End If
                'Solution10.click event, fills Solution box 11 with values based on the information in Solution box 10
            Case 9
                If Solution10.Items.Count > 0 Then
                    Dim Root11 =
                    (
                    From k In doc...<Section10>
                    Where k.@id = Solution10.Text
                    From l In k.<Root11>.<Section11>
                    Select l.@id
                    ).ToArray
                    Solution11.Items.Add(Root11)
                End If
                'Solution11.click event, fills Solution box 12 with values based on the information in Solution box 11
            Case 10
                If Solution11.Items.Count > 0 Then
                    Dim Root12 =
                    (
                    From l In doc...<Section11>
                    Where l.@id = Solution11.Text
                    From m In l.<Root12>.<Section12>
                    Select m.@id
                    ).ToArray
                    Solution12.Items.Add(Root12)
                End If
        End Select
    End Sub
			
				Last edited: 
			
		
	
								
								
									
	
		
			
		
		
	
	
	
		
			
		
		
	
								
							
							 
	 
 
		 
 
		 
 
		