Is it possible to filter values (remove them) fr0m a drop-down list box with values from a SharePoint list? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Is it possible to filter values (remove them) fr0m a drop-down list box with values from a SharePoint list?

Last post 04-20-2018 09:55 AM by Paradiddle. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 04-18-2018 01:03 PM

    Is it possible to filter values (remove them) fr0m a drop-down list box with values from a SharePoint list?

     I have a dropdown list box that is populated from a SharePoint list.  Is it possible to filter the values in the dropdown from values in another SharePoint list?

    For example, a dropdown list is populated with values from SharePoint list call it Alpha and has values (Red, Blue, Green, Black, Yellow).  A second SharePoint list call it Beta contains the values (Blue and Green).  I would like to filter the dropdown so it only contains (Red, Blue, Green, Black, Yellow).

    Thanks for any assistance.

  • 04-20-2018 09:00 AM In reply to

    Re: Is it possible to filter values (remove them) fr0m a drop-down list box with values from a SharePoint list?

    Here's a sample that may help you - save the file locally, right click and select Design, then preview to see the functionality.
    Hilary Stoupa

  • 04-20-2018 09:55 AM In reply to

    Re: Is it possible to filter values (remove them) fr0m a drop-down list box with values from a SharePoint list?

     Well, Hillary I wish I was a smart as you.  Thanks.

    I did it in code which works I guess it's just not as elegant.

     

    First chunk of code goes in FormEvents_Loading 

      using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                {
                    SPWeb web = site.OpenWeb(SPContext.Current.Web.ID); //grab the current web

                    RemoveFirstItem();

                    SPList list = web.Lists["FirstList"];
                    SPView view = list.Views["FirstListView"];
                    SPListItemCollection listItems = list.GetItems(view);

                    List<string> DoHickies= new List<string>();

                    foreach (SPListItem item in listItems)
                    {

                        string myValue = item["FieldName"].ToString();


                        if (!String.IsNullOrWhiteSpace(myValue) && myValue.StartsWith("6-"))
                        {
                            DoHickies.Add(myValue);
                        }
                    }

                    SPList listRemove = web.Lists["ListTwo"];
                    SPListItemCollection listRemoveItems = listRemove.Items;
                    foreach (SPListItem item in listRemoveItems)
                    {
                        string myValue = item["FIELDNAME"].ToString();

                        if (!String.IsNullOrWhiteSpace(myValue) && myValue.StartsWith("6-"))
                        {
                            try
                            {
                                DoHickies.Remove(myValue);
                            }
                            catch
                            {
                            }
                        }
                    }

                    foreach (var thing in DoHickies)
                    {
                        AddItem(thing, thing);
                    }

                    RemoveFirstItem();
                    if (web != null)
                    {
                        web.Dispose();
                    }
                }

     

    private void AddItem(string itemId, string itemName)
            {
                XPathNavigator DOM = DataSources["choices"].CreateNavigator();
                XPathNavigator group1 = DOM.SelectSingleNode("//options", NamespaceManager);
                XPathNavigator field1 = DOM.SelectSingleNode("//options/option", NamespaceManager);
                XPathNavigator newNode = field1.Clone();
                newNode.SelectSingleNode("value").SetValue(itemId);
                newNode.SelectSingleNode("displayname").SetValue(itemName);
                group1.AppendChild(newNode);
            }  

       private void RemoveFirstItem()
            {
                XPathNavigator DOM = DataSources["choices"].CreateNavigator();
                XPathNavigator group1 = DOM.SelectSingleNode("//options", NamespaceManager);
                XPathNavigator field1 = DOM.SelectSingleNode("//options/option", NamespaceManager);
                field1.DeleteSelf();
            }

     Thanks to S.Y.M for most of the code above. She is also a genius: http://www.bizsupportonline.net/infopath2007/programmatically-fill-populate-drop-down-list-box-infopath-2007.htm

     

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