ITPub博客

首页 > Linux操作系统 > Linux操作系统 > datagridview用XML做数据源的读写

datagridview用XML做数据源的读写

原创 Linux操作系统 作者:fangqm 时间:2011-05-12 19:17:18 0 删除 编辑
private void Form1_Load(object sender, EventArgs e)
    {
       
string xml=@"
                   
                     
                        hello
                        123
                     

                     
                        world
                        456
                     

                   
";

        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");                          //<---
        }
    }

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23109131/viewspace-695159/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-03-24

  • 博文量
    298
  • 访问量
    729501