Getting value from ComboBox Secondary Data into a Text Field - InfoPath Dev
in

InfoPath Dev

Getting value from ComboBox Secondary Data into a Text Field

Last post 11-07-2011 05:37 PM by JAWSURGEON. 20 replies.
Page 1 of 2 (21 items) 1 2 Next >
Sort Posts: Previous Next
  • 11-07-2011 06:45 AM

    Getting value from ComboBox Secondary Data into a Text Field

     I am trying to get a field from a datasource linked to a combobox into a text field..but having a maddening time

    The datasource is: tblDiagcode

    Field 1: strDiagcode

    Field 2: strDiagDescr

     

    1. The cboBox is bound to field =  strICDMcode ; xpath = /my:myFields/my:Exam/my:grpICDM/my:grpICDMCodes/my:cboICDMCode

     2. the text field is xpath = /my:myFields/my:Exam/my:grpICDM/my:grpICDMCodes/my:fldICDM_Text

     The code should fire after the 'changed' event in the combobox:

    Dim ICDMdata As XPathNavigator = Me.DataSources("tblDiagCode").CreateNavigator

    'create an xpnavigator object positioned onthe current site; which is the cboICDMcod

    Dim ICDMcode As XPathNavigator = e.Site.CreateNavigator

    'lookup the value of the ICDM description in tblDiagCode where cboICDMCode = [tblDiagCode].[strDiagcode]

    Dim ICDMdescr As String = ICDMdata.SelectSingleNode("/ICDMdata[strDiagCode ='" _
         & e.NewValue & "']/strDiagDescr", Me.NamespaceManager).Value

    '''CODE CRASHES in ABove line

    '{"Expression must evaluate to a node-set."}

    MessageBox.Show(ICDMdescr)

    'set the value of ICDMCode_text (which is the second column of the table on the same row as the cbo box) to ICDMDescr

    ICDMcode.SelectSingleNode(

    "../my:ICDMdescr", Me.NamespaceManager).SetValue(ICDMdescr.ToString)

     

  • 11-07-2011 09:49 AM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

    I'll have to ask my usual annoying questions here - is there a reason you need to do this in code?

    My guess would be that the XPath you are using to select the strDiagDescr is incorrect. Can you right-click that node in the data source task pane and copy the XPath? 

    Hilary Stoupa

  • 11-07-2011 11:13 AM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

    Thanks for reply

    As to question #1: I am used to event based programming in MSFT apps...so I thought this would be a good way to do it...and I could learn from it and re-use the technique

    #2. Here is the xpath: to the textBox:  /my:myFields/my:Exam/my:grpICDM/my:grpICDMCodes/my:fldICDM_Text

     While we are on the subject: do you have any good reference sources for programming Infopath (besides the MSFT site(s))

    3. If there is a better way to do this I am open to suggestions :)

    Thanks

  • 11-07-2011 11:27 AM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

    The XPath I'm interested in is in the tblDiagCode data source, as referenced in your code.

    You are getting an error here, I think:

    Dim ICDMdescr As String = ICDMdata.SelectSingleNode("/ICDMdata[strDiagCode ='" _
         & e.NewValue & "']/strDiagDescr", Me.NamespaceManager).Value 

    because the XPath you are using doesn't return a node.

    I'm afraid I generally use MSDN for my IP programming needs - you've specifically asked for non Microsoft recommendations, and I don't really have any...

    I would just use a rule to set the text box. You can set a rule on the field bound to the combo box, and when it changes, set the value of the field bound to the text box. Use the formula editor to pick the strDiagDescr node from the tblDiagCode data source. Select the Filter button when selecting the field to add an XPath filter to it.

    Hilary Stoupa

  • 11-07-2011 11:59 AM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

    Yes I use MSDN too...but in this case I have found it dreadful.

    Here, hopefully is the information you asked fo: 

    xpath to combo box =/my:myFields/my:Exam/my:grpICDM/my:grpICDMCodes/my:cboICDMCode

    ComboBox Datasource; external/stored in template: = tblDiagCode

    /dfs:myFields/dfs:dataFields/d:tblDiagCode/@strDiagCode[../@ynActive = "True"]

    Hope that helps.

    Adam 

  • 11-07-2011 12:09 PM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

    So, then, your code:

    Dim ICDMdescr As String = ICDMdata.SelectSingleNode("/ICDMdata[strDiagCode ='" _
    & e.NewValue & "']/strDiagDescr", Me.NamespaceManager).Value

    And your actual XPath:

    /dfs:myFields/dfs:dataFields/d:tblDiagCode/@strDiagCode

    So, my guess would be your code should be:

    Dim ICDMdescr As String = ICDMdata.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:tblDiagCode[@strDiagCode ='" _
    & e.NewValue & "']/@strDiagDescr", Me.NamespaceManager).Value

    Hilary Stoupa

  • 11-07-2011 12:31 PM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

    1. The Dim ICDMdescr as string...indeed retrieves the appropirate value !! thanks

    2. Since this is a repeating table; the combo box on EACH line needs to insert the right text into that text box on it's own line.

    the following code only inserts it on FIRST line of the table and no others....

    ICDMcode.SelectSingleNode(

    "/my:myFields/my:Exam/my:grpICDM/my:grpICDMCodes/my:fldICDM_Text", Me.NamespaceManager).SetValue(ICDMdescr) 

    I am guess I need to select the parent node or some other device to select the proper correspongind test box

    Code 1............................................Code1 description

    Code 2...........................................Code 2 description

    and so forth...

    BTW...I tried creating a 'rule' that looks up the data value after the user selects the combobox item... once again this has the disadvantage that it puts the same descripton in very line item.

     Thanks for all you help in advance.

    ADam

  • 11-07-2011 12:41 PM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

    If the field the combo box is bound to is in the repeating group, then it should be able to set the value of a field within the repeating group when it changes - and only the field in that instance. Attach your template under the Options tab of a reply if you'd like me to set up a rule so you can see that.

    ICDMcode is the current repeating node, right? I see you are using e.Site. The problem again, then, is your XPath - it needs to be relative. I'll guess that ICDMcode is actually at the current instance of my:grpICDMCodes...

    ICDMcode.SelectSingleNode("my:fldICDM_Text", Me.NamespaceManager).SetValue(ICDMdescr)

    Hilary Stoupa

  • 11-07-2011 12:46 PM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

    Well its not actually in a repeating group; its in the first column of a repeating table (not sure if that distinction is important here).

    I am going to return to this later this evening...and work on it.

    Thanks for now. I will touch base tomorrow if needed.

    Thanks again for all your input.

    Adam

  • 11-07-2011 12:50 PM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

    You don't want to confuse controls on the form with the actual schema structure of the form. Repeating groups can bound to a number of controls - repeating tables, repeating sections, sections that don't repeat, etc.

    As long as the field bound to the combo box is in the same repeating group as the field bound to the text box, you should be able to use a relative XPath.

    Hilary Stoupa

  • 11-07-2011 01:07 PM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

    This fixed it...now it works. I had to use the  "../"

    ICDMcode.SelectSingleNode(

    "../my:fldICDM_Text", Me.NamespaceManager).SetValue(ICDMdescr)

     I am still going to try to figure how to do the non-programmatic method since its a heck of a lot easier.

    Regards,

    Adam

  • 11-07-2011 05:37 PM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

    Hillary:

    I have spent some time trying to get the 'rules" based approach to accomplish what we just did in code..because it seems like it would be faster to implement..but I can't get it to work. I tried editing the xpath in the rule ..but that did not work.

    So what I want to accomplish is ;

    ComboBox1 : strIProcCode>>use makes choice >>>rule fires >>>>populate TextBox with strProcCodeDesc

    I set up  a 2 column repeating table with : comboBox1 and txtDescription

    Also setup a repeating section with the same fields: combobox1 and txtDesription

    I can get the comboboxes to select unique values; but the value in txtDescription remains the same thing...always;

    The Field I want to set is: /my:myFields/my:Exam/my:group106/my:group107/my:fldProcText; however I cannot enter or change the value in the Rules editor.

    The Value I want in the text box is:  xdXDocument:GetDOM("tblProcCodes")/dfs:myFields/dfs:dataFields/d:tblProcCodes[@strProcCode = '"  & e.newvalue * "']/@strProcCodeDesc

    There must be something easy that I am missing !!!

    thanks

    Adam

  • 11-07-2011 05:37 PM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

    Hillary:

    I have spent some time trying to get the 'rules" based approach to accomplish what we just did in code..because it seems like it would be faster to implement..but I can't get it to work. I tried editing the xpath in the rule ..but that did not work.

    So what I want to accomplish is ;

    ComboBox1 : strIProcCode>>use makes choice >>>rule fires >>>>populate TextBox with strProcCodeDesc

    I set up  a 2 column repeating table with : comboBox1 and txtDescription

    Also setup a repeating section with the same fields: combobox1 and txtDesription

    I can get the comboboxes to select unique values; but the value in txtDescription remains the same thing...always;

    The Field I want to set is: /my:myFields/my:Exam/my:group106/my:group107/my:fldProcText; however I cannot enter or change the value in the Rules editor.

    The Value I want in the text box is:  xdXDocument:GetDOM("tblProcCodes")/dfs:myFields/dfs:dataFields/d:tblProcCodes[@strProcCode = '"  & e.newvalue * "']/@strProcCodeDesc

    There must be something easy that I am missing !!!

    thanks

    Adam

  • 11-07-2011 05:43 PM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

    Can you attach your form to a reply? Under the Options tab...
    Hilary Stoupa

  • 11-07-2011 07:17 PM In reply to

    Re: Getting value from ComboBox Secondary Data into a Text Field

     Ok...uploaded.

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