Selecting items in one listbox and putting them into another listbox on button click - InfoPath Dev
in

InfoPath Dev

Selecting items in one listbox and putting them into another listbox on button click

Last post 11-06-2011 11:14 PM by RoseMary. 30 replies.
Page 2 of 3 (31 items) < Previous 1 2 3 Next >
Sort Posts: Previous Next
  • 04-24-2008 10:38 PM In reply to

    • rohit
    • Top 500 Contributor
    • Joined on 03-17-2008
    • Posts 50

    Re: Selecting items in one listbox and putting them into another listbox on button click

    i allready made full switch to the IP07 code model.

    Below is my code.

    XPathNavigator nav = this.MainDataSource.CreateNavigator();

    XPathNavigator oFromList = nav.SelectSingleNode("//my:List1",NamespaceManager);

    XPathNavigator oFromItem = nav.SelectSingleNode("//my:SelectJobContext", NamespaceManager); XPathNavigator oToList = nav.SelectSingleNode("//my:List2", NamespaceManager);

    XPathNavigator oToItem = nav.SelectSingleNode("//my:SelectedJobContext", NamespaceManager);

    XPathNavigator oFromItem = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:Temp",NamespaceManager);

    oFromItem = oFromList.SelectSingleNode("my:Item[.='" + sFromItem + "']", NamespaceManager);

    XPathNavigator oToItem = oToList.SelectSingleNode("my:Item[.='" + sToItem + "']", NamespaceManager);if (null != oFromItem)

    oToList.InsertAfter(oFromItem);

    My DataSource is as follows

    -myFields

    --SelectJobContext

    --SelectedJobContext

    -List1--(Group)

    --Item--(Repeating Field)

    -List2--(Group)

    --Item--(Repeating Field)

  • 04-28-2008 02:36 PM In reply to

    Re: Selecting items in one listbox and putting them into another listbox on button click

    Your code doesn't even compile:

    Error 1 A local variable named 'oFromItem' is already defined in this scope FormCode.cs 45 28
    Error 2 The name 'sFromItem' does not exist in the current context FormCode.cs 46 68
    Error 3 A local variable named 'oToItem' is already defined in this scope FormCode.cs 48 28
    Error 4 The name 'sToItem' does not exist in the current context FormCode.cs 48 79

    Also, you try to select //my:Temp, which wasn't listed in your DataSource.

    - - - - -

    Try this:

    XPathNavigator nav = this.MainDataSource.CreateNavigator();

    string sFromChoice = nav.SelectSingleNode("//my:SelectJobContext", NamespaceManager).Value;
    XPathNavigator oFromItem = nav.SelectSingleNode("//my:List1/my:Item[.='" + sFromChoice + "']", NamespaceManager);

    string sToChoice = nav.SelectSingleNode("//my:SelectedJobContext", NamespaceManager).Value;
    XPathNavigator oToItem = nav.SelectSingleNode("//my:List2/my:Item[.='" + sToChoice + "']", NamespaceManager);

    if (null != oFromItem && null != oToItem)
        oToItem.InsertAfter(oFromItem);

  • 04-28-2008 02:51 PM In reply to

    Re: Selecting items in one listbox and putting them into another listbox on button click

    I should also state that the InsertAfter() call does a copy, not a move. So if your intent was to move the item and not just copy it, then you'll need to call DeleteSelf() on the oFromItem after you insert it into the To list.

  • 04-29-2008 03:10 AM In reply to

    • rohit
    • Top 500 Contributor
    • Joined on 03-17-2008
    • Posts 50

    Re: Selecting items in one listbox and putting them into another listbox on button click

    Thanks Greg,

    It works.

    But How should i make LIstBox's property to multiple selection.

     

  • 04-29-2008 01:21 PM In reply to

    Re: Selecting items in one listbox and putting them into another listbox on button click

    IP07 includes the new Multiple-Selection List Box control which allows for multiple selections. But I have not used this control and do not know what kind of affect it will have on the effectiveness of the code you now have running. If it requries code changes when switching to that control, you'll need to figure those out on your own.

    Good luck!

  • 04-29-2008 01:21 PM In reply to

    Re: Selecting items in one listbox and putting them into another listbox on button click

    InfoPath 2003 does NOT include a multi-select box.

  • 04-29-2008 11:56 PM In reply to

    • rohit
    • Top 500 Contributor
    • Joined on 03-17-2008
    • Posts 50

    Re: Selecting items in one listbox and putting them into another listbox on button click

    is there no any way to allow  listbox control to select mulitiple values in infopath 2007.

  • 04-30-2008 12:37 PM In reply to

    Re: Selecting items in one listbox and putting them into another listbox on button click

    There is not. You will need to use the control that is designed to allow multiple selections.

  • 05-29-2008 09:12 AM In reply to

    • rohit
    • Top 500 Contributor
    • Joined on 03-17-2008
    • Posts 50

    Re: Selecting items in one listbox and putting them into another listbox on button click

    Sorry I was on long vacation.

    thanks a lot greg.

    I have one more problem :)

    How to remove item from listbox after inserting it into another list box in C#. I am using XPathNavigator.

    As you done it in javascript i.e.oFromItem.text="";

    please suggest it.

    Thanks in advance.

  • 05-31-2008 01:56 AM In reply to

    • rohit
    • Top 500 Contributor
    • Joined on 03-17-2008
    • Posts 50

    Re: Selecting items in one listbox and putting them into another listbox on button click

    Hi Greg,

    I am using

    oFromItem.DeleteSelf();

    to removing item from first list box after inserting it into another list box control as both are binds to the secondary data source,but it won't work.

     

    Please help me......

    Thanks in advance.

     

  • 06-02-2008 10:38 AM In reply to

    • SAK
    • Not Ranked
    • Joined on 05-27-2008
    • Irvine, CA
    • Posts 7

    Re: Selecting items in one listbox and putting them into another listbox on button click

    Greg/ Rohit

    I am also working to implement the same functionality. My goal is to implement a browser enabled form using InfoPath 2007 to upload in SharePoint. My first list box gets it items from SharePoint WebService. So my first list box is populating all the items with no problem. Now the problem I face is, how to move the items to second list box on click of a button.

    • Should my second list box should be a repeating field?
    • Should I need to connect my second list box to a XML file?
    • On click of a button do I need to update the XML file to add items to my second list box?
    • The example from http://www.infopathdev.com/files/folders/examples/entry279.aspx uses javascript and I believe I cannot use the same I need to have the form browser enabled.

    Please help !! Thanks

     

  • 06-03-2008 03:01 AM In reply to

    • rohit
    • Top 500 Contributor
    • Joined on 03-17-2008
    • Posts 50

    Re: Selecting items in one listbox and putting them into another listbox on button click

    Hi SAK,

     

    If you are using Infopath 2007 object model.

    then following is the solution.

    You have to bind your second list box box to repeating field of the xml file.

     

  • 06-03-2008 01:45 PM In reply to

    • SAK
    • Not Ranked
    • Joined on 05-27-2008
    • Irvine, CA
    • Posts 7

    Re: Selecting items in one listbox and putting them into another listbox on button click

    Thanks for  the reply. If I create a XML file for my second list box that would contain nothing to start with and would need to add items to that XML file whenever the user clicks on the button by selecting the items in first list box. Please confirm. Also will this XML file be created one for each form when I upload the form in to SharePoint and when users create new forms. Thanks.

  • 06-04-2008 04:34 PM In reply to

    • SAK
    • Not Ranked
    • Joined on 05-27-2008
    • Irvine, CA
    • Posts 7

    Re: Selecting items in one listbox and putting them into another listbox on button click

    I am still struggling to get this implemented. Please help. I am using InfoPath 2007 and need to upload this browser enabled form in to SharePoint

    First List Box:

    This first list box lists all the items from Sharepoint list using web service. User will be selecting one or more item from this in to second list box.

    1. I defined a data connection to receive data from SharePoint Web Service.

    2. I inserted a repeating section and then I inserted a list box control on to that.

    3. This list box is bound to non repeating field called AppListField in Main Data Source

    4. In the properties of the list box I selected "look up values from an external data source" and selected the data connection I formed in step 1 above. I have selected Id for value field and App Name for Display Name.

    5. Is it all okay?

    Second List Box 

     1. I inserted a list box control in to a repeating section.

    2. I  created a repeating group in Main Data Source

    3. The repeating section is bound to the repeating group

    4. I created another non repeating field under repeating group and bound the second list box to that. Am I right in doing this way?

    Click Event Code: 

    1. On click event of the button  I am able to get the value of the selected item from first list box in to the variable
     AppListField in MainDataSource. I donot know how to get the display name.

    2. Once I get the value I am adding it to the XML file and it never shows there. I have given the code below.

    XML File: Initially this  XML will be empty as the user has not added anything.

     <SelectedAppListGroups>
    <SelectedAppListGroup><ImpactAppId/><ImpactAppname/></SelectedAppListGroup>
    </SelectedAppListGroups>

     Code  on Button Click Event

                XPathNavigator AppListField = DOM.SelectSingleNode("/my:myFields/my:AppListField", this.NamespaceManager);  //getting selected item from first list box.
             
                DataSource ds = DataSources["ImpactAppList"];  //XML file data source tied to second list box
                XPathNavigator selectedAppList  = ds.CreateNavigator();
                XPathNavigator SelectedAppGroup = selectedAppList.SelectSingleNode("/SelectedAppListGroups/SelectedAppListGroup"); //
                XPathNavigator ImpactAppIdNode = selectedAppList.SelectSingleNode("/SelectedAppListGroups/SelectedAppListGroup/ImpactAppId");
                XPathNavigator ImpactAppnameNode = selectedAppList.SelectSingleNode("/SelectedAppListGroups/SelectedAppListGroup/ImpactAppname");

                SelectedAppGroup.AppendChildElement("", "ImpactAppId", "", AppListField.Value);
                SelectedAppGroup.AppendChildElement("", "ImpactAppname", "", "Test33"); //I am adding a dummy value because I am not able to access the display name from First List box

    Thanks in advance.

  • 06-05-2008 07:03 AM In reply to

    Re: Selecting items in one listbox and putting them into another listbox on button click

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 2 of 3 (31 items) < Previous 1 2 3 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.