WPF ListView迭代 [英] WPF ListView Iteration
问题描述
您好我有一个奇怪的要求,即通过一堆xml文件收集数据并将其绑定到Listview(WPF一个)。这部分是以某种方式完成的。但我面临的挑战是将listviewitems导出到Datatable并从那里导出到Excel或csv
我用google搜索,但是没有运气,有什么建议或例子吗?
刚看到回复....我想我需要更具体地解决我的问题
我有一堆文件(xml)我从中收集cretain节点值并将其绑定到Lisview。为此我使用了XMl来实现linq技术并将它们绑定了
以下是片段
var MethodList = 来自元素 XpedDoc.Descendants(ns + 方法)
选择元素;
foreach ( var XpedElement in MethodList)
{ do something}
LstNodeView.Items.Add(ndXped); // 添加到我的列表视图,其中ndXped是自定义类
现在在这个我希望将所有列表项导出到数据表中,以将导出到 Excel文件
希望这个帮助
xml到数据表
DataTable dt = new DataTable();
DataSet ds = new DataSet();
StringReader reader = new StringReader(Xmlstring);
ds.ReadXml(读者);
dt = ds.Tables [ 0 ];
数据表到Xml
MemoryStream str = new MemoryStream();
dt.WriteXml(str, true );
str.Seek( 0 ,SeekOrigin.Begin);
StreamReader sr = new StreamReader(str);
string Xmlstring = sr.ReadToEnd();
希望你能得到解决方案...
添加了代码块格式[/编辑]
Hi I have rather strange requirement of gathering data through bunch of xml files and binding it to Listview(WPF one). this part was somehow completed . but the challenge I have is have to export the listviewitems to an Datatable and from there to Excel or csv
I googled , but with no luck ,is there any suggestions or examples ?
Just saw the replies ....I think i need to be more specific on my problem
I have bunch of files(xml ones) from which i gather cretain node values and bind it to Lisview.For this i have used XMl to linq technique and have binded them
below is snippet
var MethodList = from Elements in XpedDoc.Descendants(ns + "Method")
select Elements;
foreach (var XpedElement in MethodList)
{ do something }
LstNodeView.Items.Add(ndXped);// adding to my list view where ndXped is custom class
Now after this I want export all listitems into datatable to export into Excel file
Hope this helps
xml to data table
DataTable dt=new DataTable(); DataSet ds = new DataSet(); StringReader reader = new StringReader(Xmlstring); ds.ReadXml(reader); dt = ds.Tables[0];
Data Table to Xml
MemoryStream str = new MemoryStream(); dt.WriteXml(str, true); str.Seek(0, SeekOrigin.Begin); StreamReader sr = new StreamReader(str); string Xmlstring= sr.ReadToEnd();
Hope you will get solution ...
[Edit]Code block formatting added[/Edit]
这篇关于WPF ListView迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!