日期:2014-05-18 浏览次数:20868 次
private void Form1_Load(object sender, EventArgs e) { string xml=@"<?xml version=""1.0"" standalone=""yes"" ?> <Department> <Student> <Name>hello</Name> <Age>123</Age> </Student> <Student> <Name>world</Name> <Age>456</Age> </Student> </Department>"; DataSet dataset = new DataSet(); dataset.ReadXml(new System.IO.StringReader(xml)); DataTable table = dataset.Tables[0]; this.dataGridView1.DataSource = table; table.RowChanged += new DataRowChangeEventHandler(OnTableChanged); //<--- table.RowDeleted += new DataRowChangeEventHandler(OnTableChanged); //<--- } void OnTableChanged(object sender, DataRowChangeEventArgs e) { System.Diagnostics.Trace.TraceInformation("DataTable changed - " + e.Action); DataTable table = sender as DataTable; if (table != null) { table.DataSet.WriteXml("c:\\temp\\temp.xml"); //<--- } }
------解决方案--------------------