none
Deleting items from a listbox RRS feed

  • Question

  • Hi All,
    I am currently using Infopath Listbox and populating its items from SharePoint list. I want to clear all the items in this list box on a button click. Could any one suggest me how to clear all the items. I am trying to iterate through the NamesGroup folder which is of repeating type. It has two fields Value and Display Name which are linked to my list box.

    XPathNodeIterator xnNodeIterator = xnOneLevelBelow.Select("/my:myFields/my:NamesGroup", nsManager);  
    while(xnNodeIterator.MoveNext())  
    {  
                xnNodeIterator.Current.DeleteSelf();  
                if(xnNodeIterator.Current.HasChildren)  
                  xnNodeIterator.Current.MoveToFirstChild();  

     I want to delete all the items in the list box. When I execute the code, it is giving me an error and the list box becomes unusable. I mean it does not allow me to add new items to it.

    Any help would be helpful.

    Thanks
    Regards
    Sridhar

    Sunday, September 28, 2008 7:47 AM

All replies

  • Sridhar4sharepoint said:

    Hi All,
    I am currently using Infopath Listbox and populating its items from SharePoint list. I want to clear all the items in this list box on a button click. Could any one suggest me how to clear all the items. I am trying to iterate through the NamesGroup folder which is of repeating type. It has two fields Value and Display Name which are linked to my list box.

    XPathNodeIterator xnNodeIterator = xnOneLevelBelow.Select("/my:myFields/my:NamesGroup", nsManager);  
    while(xnNodeIterator.MoveNext())  
    {  
                xnNodeIterator.Current.DeleteSelf();  
                if(xnNodeIterator.Current.HasChildren)  
                  xnNodeIterator.Current.MoveToFirstChild();  

     I want to delete all the items in the list box. When I execute the code, it is giving me an error and the list box becomes unusable. I mean it does not allow me to add new items to it.

    Any help would be helpful.

    Thanks
    Regards
    Sridhar



    What kind of error are you getting? What does it say? And have you tried creating a separate group under my:myFields and putting your repeating node my:NameGroup under that? That's the usual way of creating a repeating node in the Main data source. 

    FWIW, I do not have issues if I delete all of the items in a list box and then try to add a new one. The method that I use to delete all of the items is by using DeleteRange() as described in step 6 of this article. I'll soon isolate that piece of code and write a separate article for it.

    S.Y.M. Wong-A-Ton
    www.bizsupportonline.net - InfoPath tutorials, articles, and solutions
    Monday, September 29, 2008 5:33 AM