3

I have the code on a clicked event to reset a repeating node (deleting all existing rows - see code)... I am looking for the best way to add back a default row. I tried using xmlwriter, but this requires listing all columns of the repeating node, in this case more than 40 columns - just not efficient! The default row is the basis for creating many rows programmatically. The property 'Allow users to insert and delete' is not an option because of how the form functions.

public void NewResetHiddenUntilSubmitted_Clicked(object sender, ClickedEventArgs e)
    {
        XPathNavigator root = MainDataSource.CreateNavigator();

        // Count the amount of Rents nodes
        XPathNodeIterator iter = root.Select(
       "/my:RepeatingTable",
       NamespaceManager);
        int rentsNodesCount = iter.Count;

        // Retrieve the first Rents node Starting at the first row
       XPathNavigator firstRentsNodeNav =
       root.SelectSingleNode("/my:RepeatingTable[1]",
       NamespaceManager);

        // Retrieve the last Rents node
        XPathNavigator lastRentsNodeNav =
       root.SelectSingleNode("/my:RepeatingTable[" +
       rentsNodesCount.ToString() + "]",
       NamespaceManager);

        // Delete the range of nodes from the first to the last nodes
        firstRentsNodeNav.DeleteRange(lastRentsNodeNav);

        //This is where I need to add back one default row
    }
0

Thanks so much for your codes. What I did to get the row is I delete only starting from the second row and I set the first row's value to be empty. So it's like this for my codes. Sorry it is in VB but it's similar.

              Dim iter As XPathNodeIterator = root.Select("/my:myFields/my:NewResourceType/my:NewResourceTypeRow", NamespaceManager)
              Dim rowsCount As Integer = iter.Count
              root.SelectSingleNode("/my:myFields/my:NewResourceType/my:NewResourceTypeRow[1]/my:title", NamespaceManager).SetValue("")

              firstMethodNav = _
              root.SelectSingleNode("/my:myFields/my:NewResourceType/my:NewResourceTypeRow[1+1]", _
              NamespaceManager)
            lastMethodNav = _
              root.SelectSingleNode("/my:myFields/my:NewResourceType/my:NewResourceTypeRow[" & _
              rowsCount.ToString() & "]", _
              NamespaceManager)

            firstMethodNav.DeleteRange(lastMethodNav)
  • Thanks for your thoughts! I ended up creating a default row with an xml document and applied it as follows: 'XmlDocument doc = new XmlDocument(); XmlNode group1 = doc.CreateElement("RentsRepeatingGroup", NamespaceManager.LookupNamespace("my")); XmlNode newRow = CreateOrResetRentData(true, doc, null, string.Empty, string.Empty, 0, 0, 0, false); group1.AppendChild(newRow); root.SelectSingleNode("/my:myFields/my:FinancialData/my:RentGroup/my:RentsRepeatingGroup", NamespaceManager).ReplaceSelf(group1.CreateNavigator());' – Greg Oct 30 '13 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.