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

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

问题描述

如何将可编辑的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加载到DataSet中并绑定到它。另一个解决方案是使用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的DataSource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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