使用C#,VS2008将Listview项目保存在xml文件中 [英] Save Listview items in xml file using c#,vs2008

查看:121
本文介绍了使用C#,VS2008将Listview项目保存在xml文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


在这里,我想使用C#Windows应用程序保存存储在xml文件中的listview项目.我正在使用Visual Studio2008.欢迎所有答复...

谢谢与问候,

Dhinesh Kumar.V

Hi All,


Here i wanna save listview items stored in xml file using c# windows application. Am using Visual Studio 2008. All replies welcome...

Thanks & Regards,

Dhinesh Kumar.V

推荐答案

如果您是通过datatable填充列表视图,则只需调用DataTable.WriteXML方法(不要忘记一次设置DataTable.Name) ),

如果通过其他方式,例如List< string>或Items.add,则必须手动实现序列化程序类以实现此目的.
if you populated list view via datatable then you just need to call DataTable.WriteXML method (Don''t forget to Set DataTable.Name once),

if it is via other way like List<string> or Items.add then you have to manually implement serializer class for achieve this


XElement xeRoot = new XElement("Data");
           XElement xeSubRoot = new XElement("Rows");
           foreach (var items in listView1.Items)
           {

               XDocument document = new XDocument(new XElement("Data", from item in listView1.Items.Cast<ListViewItem>()
                                                                       select new XElement("Proc", item.SubItems.Cast<System.Windows.Forms.ListViewItem.ListViewSubItem>().Select((subitem, i) => new XElement(
                                                                           i == 0 ? "PName":listView1.Columns[i].Text.ToLower(), subitem.Text)))));
               document.Save("sample.xml");
           }


这篇关于使用C#,VS2008将Listview项目保存在xml文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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