Multiple-Selection List Box checks all items even though I only selected one item - InfoPath Dev
in

InfoPath Dev

Having trouble finding a blog or post that answers your question? Check out our Custom Search Page

Multiple-Selection List Box checks all items even though I only selected one item

Last post 10-04-2012 11:02 PM by Gennady Vanin (Геннадий Ванин, Новосибирск). 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 10-04-2012 12:09 PM

    Multiple-Selection List Box checks all items even though I only selected one item

    I have a Multiple-Selection List Box that uses an external data source to populate the check box items. This data source is an xml document that gets dynamically populated in the code behind in the On_Load method from a SharePoint list with the Title field and a Check box field. I have three items in this list and all three show up in the Multiple-Selection List Box. But when I check one of the check boxes, all three of them become checked, and vice-versa. I suspect this is because my Multiple-Selection List box is bound to a single repeating field.
    \r\n

    Any suggestions on how I can check just one item in this Multiple-Selection List Box and not have every other item get checked as well?


    Edit: Here is the code from my code behind that populates the xml document that is used to back the Multiple Selection List Box


    private void PopulateIndicators(SPWeb web)
            {
                string dataConnectionName = "IndicatorList";
                RemoveFirstItem(dataConnectionName);

                SPList reasonssList = web.Lists["CIAC Test List"];

                string name = string.Empty;
                string displayValue = string.Empty;

                foreach (SPListItem item in reasonssList.Items)
                {
                    if (item["Title"] != null && item["Indicator"] != null)
                    {
                        name = item["Indicator"].ToString();
                        displayValue = item["Title"].ToString();
                    }

                    AddItem(name, displayValue, dataConnectionName);
                }

                RemoveFirstItem(dataConnectionName);
            }

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

            private void AddItem(string itemId, string itemName, string dataConnectionName)
            {
                XPathNavigator DOM = DataSources[dataConnectionName].CreateNavigator();
                XPathNavigator group1 I have a Multiple-Selection List Box that uses an external data source to populate the check box items. This data source is an xml document that gets dynamically populated in the code behind in the On_Load method from a SharePoint list with the Title field and a Check box field. I have three items in this list and all three show up in the Multiple-Selection List Box. But when I check one of the check boxes, all three of them become checked, and vice-versa. I suspect this is because my Multiple-Selection List box is bound to a single repeating field.
    \r\n

    Any suggestions on how I can check just one item in this Multiple-Selection List Box and not have every other item get checked as well?


    Edit: Here is the code from my code behind that populates the xml document that is used to back the Multiple Selection List Box


    private void PopulateIndicators(SPWeb web)
            {
                string dataConnectionName = "IndicatorList";
                RemoveFirstItem(dataConnectionName);

                SPList reasonssList = web.Lists["CIAC Test List"];

                string name = string.Empty;
                string displayValue = string.Empty;

                foreach (SPListItem item in reasonssList.Items)
                {
                    if (item["Title"] != null && item["Indicator"] != null)
                    {
                        name = item["Indicator"].ToString();
                        displayValue = item["Title"].ToString();
                    }

                    AddItem(name, displayValue, dataConnectionName);
                }

                RemoveFirstItem(dataConnectionName);
            }

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

            private void AddItem(string itemId, string itemName, string dataConnectionName)
            {
                XPathNavigator DOM = DataSources[dataConnectionName].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);

            }

  • 10-04-2012 01:13 PM In reply to

    Re: Multiple-Selection List Box checks all items even though I only selected one item

    All what your C# code-behind does is selecting all items of Multiple Selection List Box. 

    Remove Code (<Programming < Form Options < Info < File on ribbon of Infopath Designer 2010) and make sure that the properties of MSLB define data source to a sharepoint list field. Don't use checkbox field for this  

    Gennady Vanin (Novosibirsk) --- Геннадий Ванин (Новосибирск)
  • 10-04-2012 01:18 PM In reply to

    Re: Multiple-Selection List Box checks all items even though I only selected one item

    Thank you for your reply. The only thing the code in my original post does is populate the xml document before it gets connect to the MSLB. I do not know beforehand what values should be in the MSLB as they can change quite frequently. Before the form loads, the xml only has one display and one value element. The code behind adds more of these and populates them with the values from the SharePoint list. Those then go into the MSLB. My problem is when I check one of the boxes in the MSLB, they all get checked.
  • 10-04-2012 01:33 PM In reply to

     The XML file is by-product of using a sharepoint list field of type Yes/No check box to fill MSLB (here is a similar discussion though about drop-down list box but IMO it explains how XML unnecessarily comes into play when someone tries to blindly match sharepoint types/schemas as Infopath types). Use sharepoint list column of type Single line of text as data source for MSLB  

     

    Enclosed please find  here the attacjed template with my explanatory screenshots in sharepoint.stackexchange.com

    Gennady Vanin (Novosibirsk) --- Геннадий Ванин (Новосибирск)
  • 10-04-2012 01:47 PM In reply to

    Re: Multiple-Selection List Box checks all items even though I only selected one item

    You are right, I removed the xml, connected directly to the list and it worked. This method also worked (http://www.infopathdev.com/forums/p/8393/30289.aspx) but I was unable to determine which check boxes were checked in the xml after the form was submitted.

    My problem with having the MSLB pull from the SharePoint list directly is that this is for a client who has a different site collection URL then the machine I am developing on. After I publish my form and deliver to the client, is there a way to modify the site collection URL for the data connection that is bound to the MSLB? Or do I have to find out the client's site collection URL before I publish the form and enter it in somehow into the Data Connection? If I don't enter a valid url in, the Data Connection wizard won't go to the next step.
  • 10-04-2012 02:33 PM In reply to

    Re: Multiple-Selection List Box checks all items even though I only selected one item

    meyerdenney:
    You are right, I removed the xml, connected directly to the list and it worked. This method also worked (http://www.infopathdev.com/forums/p/8393/30289.aspx) but I was unable to determine which check boxes were checked in the xml after the form was submitted.
     

    That post is from 2008 and probably for Infopath 2007 where MSLB is not available in browser (only in client/filler) forms. 

    meyerdenney:
    My problem with having the MSLB pull from the SharePoint list directly is that this is for a client who has a different site collection URL then the machine I am developing on. After I publish my form and deliver to the client, is there a way to modify the site collection URL for the data connection that is bound to the MSLB? Or do I have to find out the client's site collection URL before I publish the form and enter it in somehow into the Data Connection? If I don't enter a valid url in, the Data Connection wizard won't go to the next step
     

    You mentioned that the items come to XML from sharepoint Title column and I explained above how XML file and sharepoint list field of type check box came into play. You should be able to reuse your mentioned Title column as data source (though I would not use it in the same sharepoint list if your form of type/compatibility Sharepoint List Form or Workflow Form) .


    Gennady Vanin (Novosibirsk) --- Геннадий Ванин (Новосибирск)
  • 10-04-2012 02:58 PM In reply to

    Re: Multiple-Selection List Box checks all items even though I only selected one item

     Ah, I got it now. I am using the an xml document as the data source for my MSLB. The xml document gets populated OnLoad in the code behind with the values from the list.

    My issue was I was binding the Name to the Value field to the Checkbox column in the list, when really both the Value and Display name fields should be pointed towards the Title column in the list.

    Thank you very much!

  • 10-04-2012 11:02 PM In reply to

    Re: Multiple-Selection List Box checks all items even though I only selected one item

    meyerdenney:

     Ah, I got it now. I am using the an xml document as the data source for my MSLB. The xml document gets populated OnLoad in the code behind with the values from the list.

    My issue was I was binding the Name to the Value field to the Checkbox column in the list, when really both the Value and Display name fields should be pointed towards the Title column in the list

     

    Right.

    It is quite simple and straight if to do things right from the very start and quite convoluted if to have deals with someone else's "optimizations" and fixed ideas to straighten things (like trying  to always reuse and match Sharepoint and Infopath schemas/field types, etc.)  to make them simpler than just simple.

    I really hope that all worked for you because there are a few unspecified by you details where  the devil could have managed to hide herself.

     

    Gennady Vanin (Novosibirsk) --- Геннадий Ванин (Новосибирск)
Page 1 of 1 (8 items)
Copyright © 2003-2012 Qdabra Software. All rights reserved.
View our Terms of Use.