Populating dropdown list with a LOT of items, from code - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Populating dropdown list with a LOT of items, from code

Last post 10-14-2009 07:03 AM by Patrick Halstead. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 10-12-2009 12:44 PM

    Populating dropdown list with a LOT of items, from code

    Hi everyone, I have an Infopath web form that goes out to to a DB and gets a Generic list of objects (a class called company). It then loops through that List<Company> and  adds each one to a dropdown list box in code. It works really well, but in the infopath client or in the browser, if I pull more than 2500 records from the DB for the dropdownlist - it basically locks up. I actually need to be able to pull 12,000. I don't want to setup a dataconnection and bind the dropdown listbox to that, because I get slow script problems in IE.

    does anyoen have issues with adding a lot of items to drop down listboxes?

    this is my code:

                // my loop through each company in the list.

                foreach (Company c in CompanyList)
                {

                    // method to add to the dropdown list
                    UpdateDropDownList("/my:myFields/my:Container/my:CompanyListGroup", "CompanyListItem", "CompanyListItemName", "CompanyListItemValue", c.CompanyName, c.CompanyId.ToString());

                }

      private void UpdateDropDownList(string repeatingItemGroup, string repeatingItem, string repeatingItemName, string repeatingItemValue, string name, string value)
            {
                try
                {
                    XPathNavigator root = MainDataSource.CreateNavigator();
                    XmlDocument doc = new XmlDocument();


                        XmlNode group = doc.CreateElement(repeatingItem, NamespaceManager.LookupNamespace("my"));
                        XmlNode field = doc.CreateElement(repeatingItemName, NamespaceManager.LookupNamespace("my"));
                        XmlNode node = group.AppendChild(field);
                        node.InnerText = name; // set the display field

                        field = doc.CreateElement(repeatingItemValue, NamespaceManager.LookupNamespace("my"));
                        node = group.AppendChild(field);
                        node.InnerText = value; // set the underlying value
                        doc.AppendChild(group);
                   
                   // binding to the xml doc

                    MainDataSource.CreateNavigator().SelectSingleNode(repeatingItemGroup, NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());


                }
                catch (Exception ex)
                {
                    throw (ex);
                }
     

  • 10-14-2009 07:03 AM In reply to

    Re: Populating dropdown list with a LOT of items, from code

    The problem isn't wizard vs. code, but rather whether you display in the view. Each item in a dropdown box is going to be a window control, so you are talking about lots of UI elements which will be hard for InfoPath to handle above several thousand and you can forget about the browser-form working.

    You can load the data into a secondary DOM (data source) and use a filter in the form to view it. That'll be faster. I recommend using a text box filter - you can ask your users to enter 3 characters to match and then do a "contains" query on the values you pulled down and populate the dropdown with just the matches. That should reduce the number of window controls and be more manageable.

     

    Patrick Halstead
    Project Manager at Qdabra
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.