C# 如何在 WinForms 项目中使用 XML 作为 DataGridView 的数据源?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/265604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I use XML as a DataSource for a DataGridView in a WinForms project?
提问by JayTee
How do I link an editable DataGridView to an XML file in a WinForms project?
如何将可编辑的 DataGridView 链接到 WinForms 项目中的 XML 文件?
采纳答案by Nikki9696
The easiest way recommended by MSDN here http://msdn.microsoft.com/en-us/magazine/cc163669.aspxis to load it into a data set.
MSDN 推荐的最简单方法http://msdn.microsoft.com/en-us/magazine/cc163669.aspx是将其加载到数据集中。
Q Can you tell me the best way to bind XML data to a DataGridView control?
A The simplest possible solution is to load the XML into a DataSet and bind to that. Another solution would be to use XML serialization to create an object graph from the XML and bind to that. To bind to the raw XML, you would need to create wrapper classes that implement ITypedList, IBindingList, and ICustomTypeDescriptor.
问:您能告诉我将 XML 数据绑定到 DataGridView 控件的最佳方法吗?
A 最简单的可能解决方案是将 XML 加载到 DataSet 中并绑定到该数据集。另一种解决方案是使用 XML 序列化从 XML 创建一个对象图并绑定到它。要绑定到原始 XML,您需要创建实现 ITypedList、IBindingList 和 ICustomTypeDescriptor 的包装类。
There is an entire set of code over at DevX here and a tutorial that might help you with binding DataGridView to XML via data sets. http://www.devx.com/dotnet/Article/28678/1954
DevX 这里有一整套代码和一个教程,可以帮助您通过数据集将 DataGridView 绑定到 XML。http://www.devx.com/dotnet/Article/28678/1954
Hope this helps.
希望这可以帮助。