且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C# - 将DataGridView保存到文件并加载

更新时间:2023-12-02 20:08:34

将DataGridView绑定到DataTable,并使用DataTable
ReadXml() WriteXml()将数据读取和写入文件的方法。

Bind the DataGridView to a DataTable, and use the DataTable ReadXml() and WriteXml() methods to read and write the data to a file.

如果您有多个网格绑定到多个相关表,则可以使用DataSet表示模式并使用DataSet的 ReadXml() WriteXml()方法读取和写入整个模式。

If you ever have multiple grids bound to multiple related tables, you can represent the schema with a DataSet and use the ReadXml() and WriteXml() methods of DataSet to read and write the whole schema.

MSDN页面上有一个示例,用于 DataTable.WriteXml()

There is an example on the MSDN page for DataTable.WriteXml() that you might find helpful.