Click here to Skip to main content
15,908,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can load listview items from xml file??

my save method is :


C#
private void button_Save(object sender, EventArgs e)
        {
            System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Application.StartupPath + "\\items.xml", null);

            writer.WriteStartElement("items");
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                writer.WriteStartElement("Item");
                writer.WriteAttributeString("myitem", listView1.Items[i].SubItems[0].Text);
                writer.WriteAttributeString("subitems", listView1.Items[i].SubItems[1].Text);
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
            writer.Close();
        }
Posted
Updated 12-Oct-14 23:21pm
v2

1 solution

This might work for you
C#
XDocument xDocs = XDocument.Load("C:\\YourFile.xml");
var items = from item in xDocs.Descendants("YourData")
            select new
            {
                YourData1 = item.Element("YourData1").Value,
                YourData2 = item.Element("YourData2").Value
            };

foreach (var item in items)
{
    lvwToShowYourData.Items.Add(new { YourData1 = item.YourData1, YourData2 = item.YourData2 });
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900