C# - Saving a DataGridView to file and loading

前端 未结 2 916
鱼传尺愫
鱼传尺愫 2021-01-02 18:44

To start off, what I have is a simple Winforms app, with just a save and load button, and with a datagridview control to hold data. What I am looking to do is input some dat

2条回答
  •  别那么骄傲
    2021-01-02 19:21

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

    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.

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

提交回复
热议问题