Selecting items in one listbox and putting them into another listbox on button click - InfoPath Dev Sign in | Join | Help in Controls InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » Controls » Selecting items in one listbox and putting them into another listbox on button click 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 1 of 3 (31 items) 1 2 3 Next > Sort Posts: Oldest to newest Newest to oldest Previous Next 04-01-2008 12:08 AM rohit Joined on 03-17-2008 Posts 50 Selecting items in one listbox and putting them into another listbox on button click Reply Contact Hello all, I have run into a problem. I want to select items in one list box and have them appear in another list box on button click. Thanks, 04-01-2008 09:41 AM In reply to Greg Collins Joined on 08-08-2006 Posts 2,126 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact You can see how to do it using this sample form: Moving Items Between List Boxes, v1.1http://www.infopathdev.com/files/folders/examples/entry279.aspx Please Visit:BraintroveGreg's Paintings 04-01-2008 11:56 PM In reply to rohit Joined on 03-17-2008 Posts 50 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact Thanks Greg, But I have two list box controls in which i entered entry manually into one list box and want to add this into second list box control using C# on button click event. Please Help..... 04-02-2008 11:03 AM In reply to Greg Collins Joined on 08-08-2006 Posts 2,126 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact Sorry, you can't do this. Manually entered options are not accessible via code. You MUST populate your drop-down via your main or a seconary dom in order to do what you want. It's not hard, just create an XML file with the options you manually typed in. Please Visit:BraintroveGreg's Paintings 04-02-2008 10:22 PM In reply to rohit Joined on 03-17-2008 Posts 50 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact Thanks Greg, I am able to acces manually entered option via code using DOM.selectsinglenode("//my:ListBox1",NamespaceManager).value What i want to do.I have one listbox control named ListBox1 when i select value from it and click on button it should be apear in second listbox named ListBox2. I have tried it using below code,but it won't show value into ListBox2,but if i use TextBox it apears into textbox using same code given below. XPathNavigator DOM = this.MainDataSource.CreateNavigator();string fieldvalue = DOM.SelectSingleNode("/my:myFields/my:ListBox1", this.NamespaceManager).Value; DOM.SelectSingleNode("/my:myFields/my:ListBox2", this.NamespaceManager).SetValue(fieldvalue); Please help me....... Thanks, 04-03-2008 10:21 AM In reply to Greg Collins Joined on 08-08-2006 Posts 2,126 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact Technically, you are not accessing any manually entered option from the drop-down list box control. The control is bound to a DOM node, which stores the selected value. You are accessing that DOM node value, not any option in the drop-down list box control (InfoPath does all that work in the background). If you set up the list box to get its list of options from a repeating node, then you have full access to those options as they are stored in a DOM. This is why your technique won't work. You MUST set up a repeating list, either in the main DOM or a secondary DOM, to hold your option values. Then you can insert a new node into the second list and assing it the selected value from the first list. This is what the example code you looked at did. There's no other way to do this. Manually entered value cannot be added, removed, accessed, etc. during runtime (as described above). You will need to bite the bullet and create repeating nodes for your purposes. If you need the lists to persist, then add them to the main DOM. If they don't need to persist, then they can be in a secondary DOM. Please Visit:BraintroveGreg's Paintings 04-08-2008 11:26 PM In reply to rohit Joined on 03-17-2008 Posts 50 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact Hi Greg, I have try your example using C#,But it gives me error "Cannot convert string to IXMLDOMNode" on below line. moveListItem(oFromList, oFromItem.text, oToList, oToItem.text); I have modified code as below, IXMLDOMNode oFromList = thisXDocument.DOM.selectSingleNode("//my:List1"); IXMLDOMNode oFromItem = thisXDocument.DOM.selectSingleNode("//my:Choice1");IXMLDOMNode oToList = thisXDocument.DOM.selectSingleNode("//my:List2"); IXMLDOMNode oToItem = thisXDocument.DOM.selectSingleNode("//my:Choice2");moveListItem(oFromList, oFromItem.text, oToList, oToItem.text); oFromItem.text = ""; public void moveListItem(IXMLDOMNode oFromList, IXMLDOMNode sFromItem, IXMLDOMNode oToList, IXMLDOMNode sToItem) { try {IXMLDOMNode oFromItem = oFromList.selectSingleNode("my:Item[.='" + sFromItem + "']"); IXMLDOMNode oToItem = oToList.selectSingleNode("my:Item[.='" + sToItem + "']");if (null != oFromItem) oToList.insertBefore(oFromItem, oToItem); }catch (ex) { } } How should i implement PopulateListBox function in c#.I stuck at array implementation for push operation. Please help me.Thanks, Rohit. 04-11-2008 09:58 AM In reply to Greg Collins Joined on 08-08-2006 Posts 2,126 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact Your errors are comming from these two lines: moveListItem(oFromList, oFromItem.text, oToList, oToItem.text); public void moveListItem(IXMLDOMNode oFromList, IXMLDOMNode sFromItem, IXMLDOMNode oToList, IXMLDOMNode sToItem) The problem is that you are passing strings into the function (i.e. oToItem.text), but the function is expecting a node (IXMLDOMNode sToItem). You need to update your function to expect a string: public void moveListItem(IXMLDOMNode oFromList, string sFromItem, IXMLDOMNode oToList, string sToItem) That should do it. Please Visit:BraintroveGreg's Paintings 04-13-2008 10:14 PM In reply to rohit Joined on 03-17-2008 Posts 50 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact Thanks Greg, But How should i implement PopulateListBox function in c#.I stuck at array implementation for push operation. Thanks in advance. 04-15-2008 03:29 PM In reply to Greg Collins Joined on 08-08-2006 Posts 2,126 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact Depending on you scenario, you should not need to populate your list box via code. Moving--yes, but population should take place as part of your secondary data source. If you have a static XML file, just create the XML file with all the options pre-built in there. If you have a database or a Web service secondary data source, then querying that source should populate your list. The example code you are looking at was written quite a while ago--just as V1 SP1 was coming out and my understanding of secondary data sources was still very immature. Please Visit:BraintroveGreg's Paintings 04-16-2008 03:03 AM In reply to rohit Joined on 03-17-2008 Posts 50 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact I have created one repeating field in my primary data source and binded it to ListBox1,it shows all data of that reapeting field. I have second listbox which is binds to the repeating field. Now i want the selected value form first listbox should be added into second Listbox on button click event. below is my code please add implementation in that,or provide some other solution in C#. How should i get selected value fron listbox1 and add it to ListBox2 in my While loop. XPathNavigator DOM = this.MainDataSource.CreateNavigator(); string Item = DOM.SelectSingleNode("//my:Option1", NamespaceManager).Value; //Option1 is repeating field which i binded to ListBox1 XPathNavigator insertItem = DOM.SelectSingleNode("//my:Option2", NamespaceManager); //Option2 is repeating field which i binded to ListBox2XPathNodeIterator item = DOM.Select("//my:Option1", NamespaceManager);while (item.MoveNext()) {//string data = item.Current.Value; } Thanks, 04-21-2008 05:17 AM In reply to rohit Joined on 03-17-2008 Posts 50 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact Hi Greg, I have implemented below code using C#, But it gives error "Object reference not set to an instance of an object." at IXMLDOMNode oFromList = thisXDocument.DOM.selectSingleNode("//my:List1");IXMLDOMNode oFromList = thisXDocument.DOM.selectSingleNode("//my:List1"); IXMLDOMNode oFromItem = thisXDocument.DOM.selectSingleNode("//my:SelectJobContext");IXMLDOMNode oToList = thisXDocument.DOM.selectSingleNode("//my:List2"); IXMLDOMNode oToItem = thisXDocument.DOM.selectSingleNode("//my:SelectedJobContext"); how should i overcome this error, Thanks, 04-21-2008 04:10 PM In reply to Greg Collins Joined on 08-08-2006 Posts 2,126 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact Are you developing in InfoPath 2003 or 2007? If 2007, make sure that you are set to use the 2003 coding OM by going to Tools | Form Options | Programming: C# (InfoPath 2003 Compatible). This because you are using IP03 C# syntax. Please Visit:BraintroveGreg's Paintings 04-23-2008 10:45 PM In reply to rohit Joined on 03-17-2008 Posts 50 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact I have implemented above code in 2007, i replaced "IXMLDOMNode" with "XPathNavigator" it gives me "Schema validation found non-data type errors" error at "oToList.InsertBefore(oFromItem)". How should i resolve it? 04-24-2008 04:29 PM In reply to Greg Collins Joined on 08-08-2006 Posts 2,126 Re: Selecting items in one listbox and putting them into another listbox on button click Mark as Not AnswerMark as Answer... Reply Contact Did you make the full switch to the IP07 code model? XPathNavigator oFromItem = MainDataSource.CreateNavigator.SelectSingleNode("...your...xpath...here...", NamespaceManager); Please Visit:BraintroveGreg's Paintings Page 1 of 3 (31 items) 1 2 3 Next > Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.
Hello all,
I have run into a problem. I want to select items in one list box and have them appear in another list box on button click.
Thanks,
You can see how to do it using this sample form:
Moving Items Between List Boxes, v1.1http://www.infopathdev.com/files/folders/examples/entry279.aspx
Thanks Greg,
But I have two list box controls in which i entered entry manually into one list box and want to add this into second list box control using C# on button click event.
Please Help.....
Sorry, you can't do this. Manually entered options are not accessible via code. You MUST populate your drop-down via your main or a seconary dom in order to do what you want. It's not hard, just create an XML file with the options you manually typed in.
I am able to acces manually entered option via code using DOM.selectsinglenode("//my:ListBox1",NamespaceManager).value
What i want to do.I have one listbox control named ListBox1 when i select value from it and click on button it should be apear in second listbox named ListBox2.
I have tried it using below code,but it won't show value into ListBox2,but if i use TextBox it apears into textbox using same code given below.
XPathNavigator
DOM.SelectSingleNode(
Please help me.......
Technically, you are not accessing any manually entered option from the drop-down list box control. The control is bound to a DOM node, which stores the selected value. You are accessing that DOM node value, not any option in the drop-down list box control (InfoPath does all that work in the background). If you set up the list box to get its list of options from a repeating node, then you have full access to those options as they are stored in a DOM.
This is why your technique won't work. You MUST set up a repeating list, either in the main DOM or a secondary DOM, to hold your option values. Then you can insert a new node into the second list and assing it the selected value from the first list. This is what the example code you looked at did.
There's no other way to do this. Manually entered value cannot be added, removed, accessed, etc. during runtime (as described above). You will need to bite the bullet and create repeating nodes for your purposes. If you need the lists to persist, then add them to the main DOM. If they don't need to persist, then they can be in a secondary DOM.
Hi Greg,
I have try your example using C#,But it gives me error "Cannot convert string to IXMLDOMNode" on below line.
moveListItem(oFromList, oFromItem.text, oToList, oToItem.text);
I have modified code as below,
oFromItem.text =
{
oToList.insertBefore(oFromItem, oToItem);
}
{ }
How should i implement PopulateListBox function in c#.I stuck at array implementation for push operation.
Please help me.Thanks,
Rohit.
Your errors are comming from these two lines:
moveListItem(oFromList, oFromItem.text, oToList, oToItem.text); public void moveListItem(IXMLDOMNode oFromList, IXMLDOMNode sFromItem, IXMLDOMNode oToList, IXMLDOMNode sToItem)
The problem is that you are passing strings into the function (i.e. oToItem.text), but the function is expecting a node (IXMLDOMNode sToItem).
You need to update your function to expect a string:
public void moveListItem(IXMLDOMNode oFromList, string sFromItem, IXMLDOMNode oToList, string sToItem)
That should do it.
But How should i implement PopulateListBox function in c#.I stuck at array implementation for push operation.
Thanks in advance.
Depending on you scenario, you should not need to populate your list box via code. Moving--yes, but population should take place as part of your secondary data source. If you have a static XML file, just create the XML file with all the options pre-built in there. If you have a database or a Web service secondary data source, then querying that source should populate your list.
The example code you are looking at was written quite a while ago--just as V1 SP1 was coming out and my understanding of secondary data sources was still very immature.
I have created one repeating field in my primary data source and binded it to ListBox1,it shows all data of that reapeting field.
I have second listbox which is binds to the repeating field.
Now i want the selected value form first listbox should be added into second Listbox on button click event.
below is my code please add implementation in that,or provide some other solution in C#.
How should i get selected value fron listbox1 and add it to ListBox2 in my While loop.
I have implemented below code using C#,
But it gives error "Object reference not set to an instance of an object." at IXMLDOMNode oFromList = thisXDocument.DOM.selectSingleNode("//my:List1");
how should i overcome this error,
Are you developing in InfoPath 2003 or 2007? If 2007, make sure that you are set to use the 2003 coding OM by going to Tools | Form Options | Programming: C# (InfoPath 2003 Compatible). This because you are using IP03 C# syntax.
I have implemented above code in 2007, i replaced "IXMLDOMNode" with "XPathNavigator" it gives me "Schema validation found non-data type errors" error at "oToList.InsertBefore(oFromItem)".
How should i resolve it?
Did you make the full switch to the IP07 code model?
XPathNavigator oFromItem = MainDataSource.CreateNavigator.SelectSingleNode("...your...xpath...here...", NamespaceManager);