保存Listview的项目(序列化)XML文件(VB.NET) [英] Save the Items of Listview (Serialize) XML File (VB.NET)

查看:89
本文介绍了保存Listview的项目(序列化)XML文件(VB.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这里的任何人都可以帮我解决这个问题:

如何以xml格式保存listview的所有数据。

我正在使用wpf应用程序VB.NET



我的应用程序重新打开后如何才能看到表格中的数据

我坚持我的项目的这一部分。



谢谢

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

推荐答案

序列化:



To serialize:

using System.Xml.Serialization;

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

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





并反序列化:





and to deserialize:

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

    using (FileStream stream = File.OpenRead("myXmlPath"))
    {
        myListView.Items = (ListViewItemCollection)serializer.Deserialize(stream);
    }
}


这篇关于保存Listview的项目(序列化)XML文件(VB.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆