由于rlee指出,ReadXml
和WriteXml
应该工作。我将放在一起的最基本的原始示例与单元格中的复选框一起工作得很好。
public partial class Form1 : Form
{
private DataTable table;
public Form1()
{
this.InitializeComponent();
this.table = new DataTable("Table");
DataColumn col1 = new DataColumn("Check", typeof(bool));
DataColumn col2 = new DataColumn("Text", typeof(string));
this.table.Columns.Add(col1);
this.table.Columns.Add(col2);
this.table.ReadXml("test.xml");
this.dataGridView1.DataSource = this.table;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
this.table.WriteXml("test.xml");
}
}
然后保存一个名为test.xml
一个XML文件,其中.exe
文件位于:
<?xml version="1.0" standalone="yes"?>
<DocumentElement>
<Table>
<Check>true</Check>
<Text>Row 0</Text>
</Table>
<Table>
<Check>false</Check>
<Text>Row 1</Text>
</Table>
</DocumentElement>
JSON是小的,看看这个解决方案http://stackoverflow.com/questions/17398019/how -to-转换,数据表到JSON-在-C-尖锐 –