如何在 WinForms 项目中使用 XML 作为 DataGridView 的数据源? [英] How do I use XML as a DataSource for a DataGridView in a WinForms project?

查看:21
本文介绍了如何在 WinForms 项目中使用 XML 作为 DataGridView 的数据源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将可编辑的 DataGridView 链接到 WinForms 项目中的 XML 文件?

How do I link an editable DataGridView to an XML file in a WinForms project?

推荐答案

这里 MSDN 推荐的最简单方法 http://msdn.microsoft.com/en-us/magazine/cc163669.aspx 是将其加载到数据集中.

The easiest way recommended by MSDN here http://msdn.microsoft.com/en-us/magazine/cc163669.aspx is to load it into a data set.

Q 你能告诉我将 XML 数据绑定到 DataGridView 控件的最佳方法吗?

Q Can you tell me the best way to bind XML data to a DataGridView control?

A 最简单的解决方案是将 XML 加载到数据集并绑定到该数据集.另一种解决方案是使用 XML 序列化从 XML 创建对象图并绑定到该对象图.要绑定到原始 XML,您需要创建实现 ITypedList、IBindingList 和 ICustomTypeDescriptor 的包装类.

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.

DevX 这里有一整套代码和一个教程,可以帮助您通过数据集将 DataGridView 绑定到 XML.http://www.devx.com/dotnet/Article/28678/1954

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

希望这会有所帮助.

这篇关于如何在 WinForms 项目中使用 XML 作为 DataGridView 的数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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