C # generate data in DataGridView into XML file

Development environment: VS2019
code directly without more b words

  private void button1_Click(object sender, EventArgs e)
        {
           
            DataTable dt = GetDataGridView(dataGridView1);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            ds.WriteXml(File.OpenWrite(@"D:\emlout.xml"));
            MessageBox.Show("export xml file success", "note", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }

Read More: