How can I save the ID from a combo box? - InfoPath Dev
in

InfoPath Dev

How can I save the ID from a combo box?

Last post 03-02-2011 03:31 AM by troy23. 17 replies.
Page 1 of 2 (18 items) 1 2 Next >
Sort Posts: Previous Next
  • 02-16-2011 06:01 AM

    How can I save the ID from a combo box?

    I am trying to do a common thing in other languages. My combo box stores the NameID and the Name itself. I am trying to pick up the ID of a combo box field and save it to a table that would hold the data of the infopath form. Is it possible to reference the control in code and pick up the ID so that I can send it to a save procedure?
  • 02-18-2011 11:36 AM In reply to

    Re: How can I save the ID from a combo box?

    Hey there --

    The combo box value is probably the ID, right? And the Name is the display? This means that you can get the value of the field the combo box is bound to in order to get the ID. Are you using IP 2007? Here is a blog post that shows how to get the value of a field in code.

    Hilary Stoupa

  • 02-22-2011 05:58 AM In reply to

    Re: How can I save the ID from a combo box?

    Thanks for that Hilary. Before I saw your reply I actually submitted the form via a web service. The data connection wizard seemed to allow me to select my form field (combo box) and associate it with the web service property for the ID. I am also interested in your solution as I want to learn the xml side of things. I am just a little uncertain right now when I should use xml to save and populate and when I should go via data connections.
  • 02-22-2011 06:04 AM In reply to

    Re: How can I save the ID from a combo box?

    Forgot to mention - it is InfoPath 2007
  • 02-22-2011 07:38 AM In reply to

    Re: How can I save the ID from a combo box?

    I can now get the ID using the code you suggested. Incidentally - how does one retrieve the display value instead of the id? Is there something that needs adding or changing in this code in order to access the display value? Dim nav As XPathNavigator = MainDataSource.CreateNavigator() Dim fieldValue As String = nav.SelectSingleNode("//my:field1", NamespaceManager).Value
  • 02-22-2011 07:58 AM In reply to

    Re: How can I save the ID from a combo box?

    If your combo box is populated from a secondary data source, you could get the "display" value from that, using the "value" from your combo box field as part of your XPath filter.

    If your combo box is simply hardcoded, with the values in the control itself, there is no way to get those display values in code.

    Hilary Stoupa

  • 02-23-2011 04:17 AM In reply to

    Re: How can I save the ID from a combo box?

    Thanks. It is coming from a secondary data source (web service). But how do I refer to it in the XML for example? This code will get me the ID which is great, but what needs changing in order to get the display value? Dim fieldValue As String = nav.SelectSingleNode("//my:cboNames", NamespaceManager).Value
  • 02-24-2011 05:20 AM In reply to

    Anyone know how to get selected text from a combo box?

    I can get the selected combo box ID by using Dim fieldValue As String = nav.SelectSingleNode("//my:cboNames", NamespaceManager).Value But how do I pick up the selected text? Thanks.
  • 02-24-2011 08:10 AM In reply to

    Re: How can I save the ID from a combo box?

    Is there a reason you're trying to access the value using code?

    Perhaps this thread will prove helpful:

    http://www.infopathdev.com/forums/p/15194/53864.aspx#53864

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-24-2011 08:25 AM In reply to

    Re: How can I save the ID from a combo box?

    It's hard to know when to use code, XML etc in InfoPath. Thanks for the example, but as a newbie I am unsure how it is working. Can you shed any light? Thanks
  • 02-24-2011 03:00 PM In reply to

    Re: How can I save the ID from a combo box?

    What may help is more info on what you are trying to accomplish.

    Since a secondary data source provides the values for your combo box, try this.

    On your form, put an expression box (calculated value in IP 2010). Set the value of this expression box to the field in your secondary data source that provides the data for your combo box.

    When you set the value, you'll use Insert Field or Group from the Formula Editor, You can click Filter Data right after you select the field that is your Display for you combo box. For you filter, you'd use the field that is being used for the value of your combo is equal to the field the combo box is bound to.

    I'm attaching a sample form.

    I'd say you should try to avoid using code in InfoPath, especially as a newbie, unless you are a programmer and can use MSDN to help you understand the possibilities and pitfalls. Especially for something like this, that can be done using the UI (general retrieval of data from data sources). Of course, a certain amount depends on what your end goal is.

    Hilary Stoupa

  • 02-25-2011 02:04 AM In reply to

    Re: How can I save the ID from a combo box?

    Thanks for the reply. After downloading your sample I was unable to open it - some message about domain level permission and it being needed to be open from the original location. Anyway - I think I can see what you are saying. I have attached some screen shots of the issue. When following what you said - it works somewhat, but I still only get the ID appearing in the expression box.
  • 02-25-2011 02:10 AM In reply to

    Re: How can I save the ID from a combo box?

    The other image I mean to attach contains the properties of the combo box.
  • 02-25-2011 02:43 AM In reply to

    Re: How can I save the ID from a combo box?

    Ok I got a bit further, but it still does not give me anything other than the ID. My mistake was that I was taking the main data source rather than selecting from the dropdown of available data sources. Now I can see the fields available in the combo box I am using. What I am trying to achieve is to pick up the selected text in the combo box which I could use elsewhere in code. Very easy to do in MS Access by taking the after update event of the dropdown and picking up the text value of the dropdown. Very easy to do in VB.Net by taking the text or selectedtext value of the dropdown and binding to a variable. Not immediately easy though in InfoPath it seems.
  • 02-25-2011 08:39 AM In reply to

    Re: How can I save the ID from a combo box?

    To open the downloaded sample, right click on the XSN and select Design.

    I'm going to ask again what you are doing in code -- is it something that simply can't be acheived in the IP UI?

    If you are going to use code, you need to create a navigator for the secondary data source, then select the Column1 field where the EmployeeID matches the cboNames field (if that is the one bound to the combo box in question). Since this is a combo box, what will you do for the instances where a user types in "John Smith" rather than selecting from the existing options?

    Hilary Stoupa

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