Populate text box - InfoPath Dev
in

InfoPath Dev

Populate text box

Last post 03-10-2010 07:07 AM by newbie999. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 03-03-2010 09:56 AM

    Populate text box

    Hello, 

    I am very new to InfoPath, so please bear with me.

    On my form, I have a button, 2 text boxes and on rich text text box.  The first text box, the user is to type in an id and click the button. I want to fetch the value in text box, do a look up in TFS based on that and then put the information in the other text boxes.  I have written code for the button_clicked event that does the look up in TFS and returns the correct data.  I have 2 issues:

    1.  How do I get the text in the first text box so that the button_clicked event can use it to do the look up.  Right now, I've saved the text in the text box into a private variable in the textbox_Changed event, which I then use in the button_Clicked event.  Is this right, or is there another way to do it.  In C#, you can use the Text propery and get the text in a text box, but i don't see anything like that here. 

    2.  I'm having trouble displaying information in the second text box and the rich text box.  I have the strings saved in code under the button_Clicked event, but I don't know how to get it those strings into the textboxes.

    Thanks.

    Filed under:
  • 03-03-2010 03:28 PM In reply to

    Hi, and welcome to the forum:

    You can use XPathNavigator to get data from your main data source and to set values in your main data source. You sound as if you are code savvy, so here's a link to an MSDN article on Working with XML Data Using the XPathNavigator Class in InfoPath 2007 Form Templates

    Hilary Stoupa

  • 03-09-2010 01:51 PM In reply to

    Thank you for the link.  This works fine, I can get the values from TFS and populate textboxes.  However, I have a repeating section so I want the user to be able to enter the id, click a button and get TFS information for the ID.  The user may then click the "Insert item" to bring up a new section with 3 textboxes and a button.  The user may then input another id and click the button, which should populate the TFS information into the textboxes of the newly added section. The problem is that the TFS information needs to populate the correct section, i.e., the one with the corresponding ID.  I've used XPathIterator to go through the nodes and figure out which one needs to be populated, but I don't know how to write the information to any textboxes besides the ones in the first section. 

     XML:

     <my:workItemIdTextBox></my:workItemIdTextBox>
     <my:techTextBox></my:techTextBox>
     <my:abstractTextBox></my:abstractTextBox>
     <my:group1>
      <my:group2>
       <my:workItemId>1234</my:workItemId>
       <my:field1>DeveloperA</my:field1>
       <my:field2>Do work</my:field2>
      </my:group2>
     <my:group2>
      <my:workItemId>5678</my:workItemId>  
      <my:field1></my:field1> 
      <my:field2></my:field2>
      </my:group2></my:group1>
     <my:group3>
      <my:group4>
       <my:field7></my:field7>
      </my:group4>
     </my:group3>
    </my:myFields>

    The code below allows me to find the node with id=5678, but I cannot access field1 and field2 for it.  I can only access field 1 and field 2 for the node with workItemID=5678

     

    XPathNavigator root = this.MainDataSource.CreateNavigator();

    XPathNodeIterator workItemNodes = root.Select("/my:myFields/my:group1/my:group2/my:workItemId", NamespaceManager);

    while (workItemNodes.MoveNext())

    {XPathNavigator node = nodes.Current;

     

    if (workItemNodes.Current.Name.Equals("my:workItemId"))

    {

    if (workItemNodes.Current.Value.Equals(id.ToString()))  //id is passed in

    {

    Console.WriteLine("Found work item");   //found node with id=5678, but how to access its fields to do Set?

    }

     }

     

     

  • 03-10-2010 07:07 AM In reply to

    Please disregard....I figured it out.  :)

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