title: populating datagridview with data from XML file. edit and save back to XML C#
body: <p>Here is my code to write my xml code. for this xml code i am combining two table to get the specific format for my xml</p>
  
  <pre><code>using (XmlWriter xmlWriter = XmlWriter.Create(path, xmlWriterSettings))
  {
      xmlWriter.WriteStartElement("Address");
      xmlWriter.WriteStartElement("Work");
      foreach (DataRow dataRow in dt.Rows)
      {
          xmlWriter.WriteStartElement("MD");
          foreach (DataColumn dataColumn in dt.Columns)
          {
             xmlWriter.WriteElementString(dataColumn.ColumnName, dataRow[dataColumn].ToString());
          }
          xmlWriter.WriteEndElement();
      }
      xmlWriter.WriteEndElement();//&lt;/Work&gt;
      xmlWriter.WriteStartElement("Persons");
      foreach (DataRow dataRow in dt2.Rows)
      {
          xmlWriter.WriteStartElement("Person");
          foreach (DataColumn dataColumn in dt2.Columns)
          {
               xmlWriter.WriteElementString(dataColumn.ColumnName, dataRow[dataColumn].ToString());
          }
          xmlWriter.WriteEndElement();//&lt;/Person&gt;
      }
      xmlWriter.WriteEndElement();//&lt;/Persons&gt;
      xmlWriter.WriteEndElement();//&lt;/Address&gt;
  }
  </code></pre>
  
  <p>XML file:</p>
  
  <pre><code>&lt;Address&gt;
    &lt;Work&gt;
       &lt;Location&gt;
          &lt;Location_ID&gt;1&lt;/Location_ID&gt;
          &lt;Location_NAME&gt;Virginia&lt;/Location_NAME&gt;
       &lt;/Location&gt;
    &lt;/Work&gt;
    &lt;Persons&gt;
       &lt;Person&gt;
          &lt;Person_ID&gt;1&lt;/Person_ID&gt;
          &lt;Person_Name&gt;MARA&lt;/Person_Name&gt;
          &lt;Location_ID&gt;1&lt;/Location_ID&gt;
          &lt;IsRequired&gt;0&lt;/IsRequired&gt;
       &lt;/Person&gt;
       &lt;Person&gt;
          &lt;Person_ID&gt;2&lt;/Person_ID&gt;
          &lt;Person_Name&gt;Tanner&lt;/Person_Name&gt;
          &lt;Location_ID&gt;1&lt;/Location_ID&gt;
          &lt;IsRequired&gt;0&lt;/IsRequired&gt;
       &lt;/Person&gt;
       &lt;Person&gt;
          &lt;Person_ID&gt;3&lt;/Person_ID&gt;
          &lt;Person_Name&gt;Carlo&lt;/Person_Name&gt;
          &lt;Location_ID&gt;1&lt;/Location_ID&gt;
          &lt;IsRequired&gt;0&lt;/IsRequired&gt;
       &lt;/Person&gt;
       &lt;Person&gt;
          &lt;Person_ID&gt;4&lt;/Person_ID&gt;
          &lt;Person_Name&gt;Casey&lt;/Person_Name&gt;
          &lt;Location_ID&gt;1&lt;/Location_ID&gt;
          &lt;IsRequired&gt;0&lt;/IsRequired&gt;
       &lt;/Person&gt;
    &lt;/Person&gt;
  &lt;Address&gt;
  </code></pre>
  
  <p>my problem is i want the person_id to always be a count of the persons on the file. for example when i delete data of Tanner in the above xml. the XML should look like this</p>
  
  <pre><code>&lt;Address&gt;
    &lt;Work&gt;
       &lt;Location&gt;
          &lt;Location_ID&gt;1&lt;/Location_ID&gt;
          &lt;Location_NAME&gt;Virginia&lt;/Location_NAME&gt;
       &lt;/Location&gt;
    &lt;/Work&gt;
    &lt;Persons&gt;
       &lt;Person&gt;
          &lt;Person_ID&gt;1&lt;/Person_ID&gt;
          &lt;Person_Name&gt;MARA&lt;/Person_Name&gt;
          &lt;Location_ID&gt;1&lt;/Location_ID&gt;
          &lt;IsRequired&gt;0&lt;/IsRequired&gt;
       &lt;/Person&gt;
       &lt;Person&gt;
          &lt;Person_ID&gt;2&lt;/Person_ID&gt;
          &lt;Person_Name&gt;Carlo&lt;/Person_Name&gt;
          &lt;Location_ID&gt;1&lt;/Location_ID&gt;
          &lt;IsRequired&gt;0&lt;/IsRequired&gt;
       &lt;/Person&gt;
       &lt;Person&gt;
          &lt;Person_ID&gt;3&lt;/Person_ID&gt;
          &lt;Person_Name&gt;Casey&lt;/Person_Name&gt;
          &lt;Location_ID&gt;1&lt;/Location_ID&gt;
          &lt;IsRequired&gt;0&lt;/IsRequired&gt;
       &lt;/Person&gt;
    &lt;/Person&gt;
  &lt;Address&gt;
  </code></pre>