title: c# Save DataGridView to Xml file
body: <p>This is my button to save file:</p>
  
  <pre><code>private void metroButton12_Click(object sender, EventArgs e) // save
  {
      DataSet ds = (DataSet)dataGridView1.DataSource;
      SaveFileDialog sfd = new SaveFileDialog();
      sfd.Filter = "XML|*.xml";
      if (sfd.ShowDialog() == DialogResult.OK)
      {
          try
          {
              ds.Tables[0].WriteXml(sfd.FileName);
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex);
          }
      }
  }
  </code></pre>
  
  <p>I try to safe my datagridview to XML but nothing happpend when I choose file.
  When I start console I see this:
  System.NullReferenceException: The object reference was not set to an object instance. </p>
  
  <p>My gridview look like: 
  ID    Name
  1     Michale
  2     Noob</p>
  
  <p>What am I doing here wrong?.. I saw a lot of thing's on the web but could not find any solutions in stackoverflow and other forums.
  Please be patient for newbie guys. Thank you!</p>