Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
does anybody here can help me with this question:
How i can save all data of my listview in xml format.
I'm working with wpf application VB.NET

How I could see the data in my table after my application is reopen
I'm stuck with this part of my project.

Thanks
Posted

1 solution

To serialize:

C#
using System.Xml.Serialization;

XmlSerializer serializer = new XmlSerializer(typeof(ListViewItemCollection));

using (FileStream stream = File.OpenWrite("myXmlPath"))
{
    serializer.Serialize(stream, myListView.Items);
}


and to deserialize:

C#
if (File.Exists("myXmlPath"))
{
    XmlSerializer serializer = new XmlSerializer(typeof(ListViewItemCollection));

    using (FileStream stream = File.OpenRead("myXmlPath"))
    {
        myListView.Items = (ListViewItemCollection)serializer.Deserialize(stream);
    }
}
 
Share this answer
 
v2
Comments
Johnny J. 3-Jul-13 4:39am    
OK; that was C#, I only just now saw that you're using VB. But the principle is exactly the same in VB.

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