使用 c# 将项目从 xml 填充到 Datagridview 的任何方法 [英] Any way to populate items from xml to Datagridview using c#
本文介绍了使用 c# 将项目从 xml 填充到 Datagridview 的任何方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究数据网格视图.在其中我必须显示从 xml 到网格视图列的列的值.我有这样的 xml:-另外我有一个网格视图,它有两列ID"和NAME",我想将值从 xml 填充到网格视图中.有人可以帮忙吗?
I'm working on the datagridview. In which i have to show the values of the column from the xml to the grid view column. I have xml like this:- Also i have a grid view which have two column "ID" and "NAME",I want to populate the values from the xml to grid view .Can anyone help?
<employee>
<empdetails id="1" name="sam"/>
<empdetails id="2" name="robin"/>
<empdetails id="3" name="victor"/>
</employee>
推荐答案
您可以像这样读取 xml 到 DataSet 并将 DataSet empdetails
表传递给 DataGridView:
You can read xml to DataSet and pass DataSet empdetails
table to DataGridView like this:
//Create xml reader
XmlReader xmlFile = XmlReader.Create("fullPathToYourXmlFile.xml", new XmlReaderSettings());
DataSet dataSet = new DataSet();
//Read xml to dataset
dataSet.ReadXml(xmlFile);
//Pass empdetails table to datagridview datasource
dataGridView.DataSource = dataSet.Tables["empdetails"];
//Close xml reader
xmlFile.Close();
这篇关于使用 c# 将项目从 xml 填充到 Datagridview 的任何方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文