Delete rows when checkbox is false - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Delete rows when checkbox is false

Last post 03-08-2023 05:47 AM by joubin. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 03-06-2023 06:44 AM

    • joubin
    • Not Ranked
      Male
    • Joined on 03-13-2018
    • Poland
    • Posts 14

    Delete rows when checkbox is false

     I have a simple requirement, but cannot figure out the code:

    having a repeating table with several columns and a 'verified' checkbox.

    on button click, delete all rows of a repeating table where the checkbox is not checked, so leaving only the rows with checked boxes.

    Filed under: , ,
  • 03-06-2023 08:32 AM In reply to

    Re: Delete rows when checkbox is false

    Can you post your current code? I was trying to set up a test, but it looks like I don't have my machine set up correctly for adding code to InfoPath at the moment....
    Hilary Stoupa

  • 03-07-2023 12:43 AM In reply to

    • joubin
    • Not Ranked
      Male
    • Joined on 03-13-2018
    • Poland
    • Posts 14

    Re: Delete rows when checkbox is false

    Sure. I'm lucky to found an old Win7 machine with IP2010 (VSTA integrated) installed... it is such a hassle with new 2013 and VisualStudio... currently I have this code, which deletes everything on button click:
    XPathNavigator domNav = MainDataSource.CreateNavigator(); XPathNodeIterator tableRows = domNav.Select("/my:myFields/my:Invoices_List/my:group6", NamespaceManager); DialogResult v = MessageBox.Show("Do you want to erase entire data?", "Invoices Data Table", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (v == DialogResult.Yes) { if (tableRows.Count > 0) { for (int i = tableRows.Count; i > 0; i--) { XPathNavigator reTable = MainDataSource.CreateNavigator(); XPathNavigator reTableRows = reTable.SelectSingleNode("/my:myFields/my:Invoices_List/my:group6[" + i + "]", NamespaceManager); reTableRows.DeleteSelf(); }
  • 03-07-2023 07:27 AM In reply to

    Re: Delete rows when checkbox is false

    Perfect, thanks. So if you just want to get the rows where the checkbox is not true, you would add an XPath filter to your tableRows selector.

    Let's pretend the field bound to the checkbox is field3, ok? You could also check that the field = false instead of != true, but I guess I'm assuming any blanks should also be deleted:

    XPathNodeIterator tableRows = domNav.Select("/my:myFields/my:Invoices_List/my:group6[my:field3 != 'true']", NamespaceManager);

    Hilary Stoupa

  • 03-07-2023 08:14 AM In reply to

    • joubin
    • Not Ranked
      Male
    • Joined on 03-13-2018
    • Poland
    • Posts 14

    Re: Delete rows when checkbox is false

    thanks Hilary, you are a star! it works, just had to change 'true' to '1'. so simple!
  • 03-07-2023 08:21 AM In reply to

    Re: Delete rows when checkbox is false

    Ah, cool - so yes, that would depend on your checkbox settings and what you are storing for true / false. Glad you have it working the way you need it to!
    Hilary Stoupa

  • 03-08-2023 05:47 AM In reply to

    • joubin
    • Not Ranked
      Male
    • Joined on 03-13-2018
    • Poland
    • Posts 14

    Re: Delete rows when checkbox is false

    quick addition: I had to put: [my:Duty != 1 or my:Duty =null] to cover cases where this strange xsi:nil="true" exists (so node is not empty or 0 but non existent)
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.