removechild strange - InfoPath Dev
in

InfoPath Dev

removechild strange

Last post 11-02-2005 04:06 PM by franck. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 11-02-2005 02:27 PM

    • nkelkar
    • Not Ranked
    • Joined on 09-30-2005
    • Canada
    • Posts 11

    removechild strange

    A very very strange removechild error, or I am missing something really important.

    Removing all rows in a repeating table using removechild with vb.net code as below:


    01 Dim numRows = thisXDocument.DOM.selectNodes("//d:Details").length()
    02 Dim deleteNode As IXMLDOMNode
    03 thisXDocument.UI.Alert("Total of " & numRows & " to be deleted")
    04 For i = 1 To numRows
    05 thisXDocument.UI.Alert("Deleting Row " & i)
    06 deleteNode = thisXDocument.DOM.selectSingleNode("//d:Details[" & i & "]")
    07 If deleteNode Is Nothing Then
    08 ' Do Nothing
    09 End If
    10 deleteNode.parentNode.removeChild(deleteNode)
    11 Next i


    Now if the Repeating Table had 10 rows, I would assume the code above removes all the 10 rows, BUT NO; It removes Rows 1,3,5,7,9 and leaves behind Rows 2,4,6,8,10. And while doing that it does alert at line number 5, 'Deleting Row 1', 'Deleting Row 2', 'Deleting Row 3', etc so on for all 10 rows. numRows contains a value of '10' at line number 01 and alerts the value correctly at line number 03

    So in the repeating table, we now have Rows 2,4,6,8,10

    Next I execute the code, and Row 4 & Row 8 (from the original table) are still there.

    Its skipping a row everytime.

    Any thoughts? I have to resolve this. Any other options to remove all rows in a repeating table?

    Thanks.
  • 11-02-2005 04:06 PM In reply to

    Hi,

    Your code can't work because when you delete the first node. everything is shifted by 1: 2 becomes 1. Next loop, you target i=2 (you then miss 1 that used to be 2) and so on.

    Try to always delete Details[1] not "i", or try to use something like:
    thisXDocument.DOM.selectNodes("/my:myFields/my:group1/my:group2")
    Dim oNN As IXMLDOMNode
    For Each oNN In thisXDocument.DOM.selectNodes("/my:myFields/my:group1/my:group2")
    oNN.parentNode.removeChild(oNN)
    Next

    Regards,

    Franck Dauché
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.