Quantcast
Channel: Active questions tagged listview - Stack Overflow
Viewing all articles
Browse latest Browse all 683

C#: Populate Listview from XML document

$
0
0

I want to populate my listview with data from a XML file, which is also generated with this program.

This code only adds the first entry of the XML file. But why?

XDocument document = XDocument.Load(@path + projectName +".xml");var items = from item in document.Descendants("root")            select new            {                Name = item.Element("Child").Attribute("Name").Value,                time = item.Element("Child").Attribute("time").Value            };foreach (var item in items){    var lvi = activitiesList.Items.Add(item.Name);    lvi.SubItems.Add(item.time);}

Here is my XML File

<root><Child Name="New Activity" time="20" /><Child Name="asdf1" time="5" /><Child Name="g1" time="0" /></root>

and my Listview should show this in two columns:

New Activity  20asdf1         5g1            0

Viewing all articles
Browse latest Browse all 683

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>