Programatically populate and clear a listbox - InfoPath Dev
in

InfoPath Dev

Programatically populate and clear a listbox

Last post 04-25-2011 09:07 AM by Greg Collins. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 04-19-2011 10:57 AM

    Programatically populate and clear a listbox

    I'm having a devil of a time trying to clear a listbox programatically in InfoPath 2007.

    I found this example on how to populate a listbox programatically. I was able to incorporate this example into my code and it works correctly. But I have not been able to find or write any code that will reset/clear the listbox so that I can then re-populate it from scratch. Some results I received - I've gotten error messages; I was able to clear out the listbox but was not able to re-populate it; I cleared out the listbox and it re-populated correctly, but 1 of the previous search ID values appears in the listbox.

    I've tried this, this(Part 6) and rules to clear fields, all to no avail. Any ideas on how to reset a listbox using the working example above? Or is there another working example out there that both populates and clears a listbox?

    Joe

  • 04-19-2011 03:25 PM In reply to

    Re: Programatically populate and clear a listbox

    You need to remove all the option nodes to clear out the list box.

    So you start of with something like:

    <Options>
        <Option/>
        <Option/>
        <Option/>
        <Option/>
    </Options>

    And you need to delete all the option nodes so that it looks like this in your DOM:

    <Options>
    </Options>

  • 04-21-2011 11:22 AM In reply to

    Re: Programatically populate and clear a listbox

    Hi Greg,

    I understand that, but how? I need an example that will work with the example that populates the listbox. Can you point me towards one?

    Thanks.

  • 04-25-2011 09:07 AM In reply to

    Re: Programatically populate and clear a listbox

     That example already has a RemoveFirstItem() function. A poor-man's way to accomplish this it to figure out how many options there are, and call this function that many times. But that isn't very efficient. You can try to set the InnerXml to an empty string. This works most of the time, but sometimes it gives an error. Or you can try the DeleteRange method as described here: http://vspug.com/ssa/2008/01/15/infopath-delete-file-attachments-programmatically-c/

     

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