How to fill more than one Comboboxes from C# code? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

How to fill more than one Comboboxes from C# code?

Last post 04-04-2006 11:51 AM by hcontreras. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 03-15-2006 06:40 AM

    How to fill more than one Comboboxes from C# code?

    Hi all!

    I've created a new Infopath form called FireOrder and put two comboboxes on it, they are DropDownListEmployees and DropDownListJobRole. Also I've defined two datasources EmployeeList and JobRoleList and specifed dropdownlists's datasources respectively.

    Then I am getting data from WebService as XmlNode and trying to add values for datasource programmatically:

    IXMLDOMNode documentRoot = thisXDocument.DOM.selectSingleNode("/my:FireOrder");
    IXMLDOMNode employeesList = thisXDocument.DOM.selectSingleNode("/my:FireOrder/my:EmployeesList");

    string orgunitId = thisXDocument.DOM.selectSingleNode("/my:FireOrder/my:OrgunitId").text;

    // WebService call
    XmlNode empList = fireapplication.GetEmployeesList(orgunitId);

    IXMLDOMNode newRow;
    foreach (XmlNode node in empList.ChildNodes)
    {
    newRow = employeesList.cloneNode(true);
    newRow.selectSingleNode("my:CODE").text = node.FirstChild.InnerText;
    newRow.selectSingleNode("my:EMPLOYEE").text = node.LastChild.InnerText;

    // HERE THE EXCEPTION THROWN
    documentRoot.appendChild(newRow);
    }

    and following exception is thrown when code reached commented line:

    Element 'http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-03-10T09:04:37}EmployeesList' is unexpected according to content model of parent element 'http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-03-10T09:04:37}FireOrder'.


    But the most interesting thing is that when I deleting one of the dropdownlists and its datasource this code works fine and I can see all data from WebService method has been added sucessfully!

    Does anybody knows what can cause this problem? Does Infopath can hold only one DropDownLists to be filled from C# code?
  • 03-16-2006 01:35 AM In reply to

    Re: How to fill more than one Comboboxes from C# code?

    Maybe something wrong with my XPath syntax or whole Infopath DataSource filling solution?

    Can you please show me somme better code snippet (if only it exists) for filling Infopath DataSource from C# code? I've found only this one:

    http://aspalliance.com/667
  • 03-16-2006 07:21 AM In reply to

    Re: How to fill more than one Comboboxes from C# code?

    I found the solution! :P

    The point is that Infopath Document heavy relies at it's internal xml structure. In code that was provided above I am calling

    documentRoot.appendChild(newRow);

    That works fine if I got only one DataSource of type group inside main Infopath document datasource, but when another datasource was added an exception was trown because it's name was differ from first one.

    So to fill more than one DataSources inside Infopath document, you should use something like:

    documentRoot.insertBefore(newRow, jobRolesList);

    where jobRolesList is the last added DataSource.

    Also you should always keep in mind that all C# code manipulations with Infopath DataSources will hardly depends on it's internal xml structure (xsd schema actually)
  • 04-04-2006 11:51 AM In reply to

    Re: How to fill more than one Comboboxes from C# code?

    I'm having problems trying to make this happen. I have a Client drop-down listbox and a Project drop-down listbox. I want to populate my Project drop-down listbox based on the clientName selected in the Client drop-down listbox. I have a web service (getProjectsForClient) that's sending back a DataSet.

    Can I see more sample of the actual code you used, or can you help me?

    Here is a sample of my code:

    System.Xml.XmlDataDocument projectsXMLDataDoc = new
    System.Xml.XmlDataDocument(this.RetDataset);
    XmlNode projectListXMLNode = projectsXMLDataDoc.DocumentElement;
    DataObject getProjectsForClientDataSource = thisXDocument.DataObjects[2];
    IXMLDOMNode dtClientsDataSourceNode = getProjectsForClientDataSource.DOM.selectSingleNode(
    "/*[local-name()='myFields']/*[local-name()='dataFields']/*[local-name()='getProjectsForClientResponse']/*[local-name()='getProjectsForClientResult']/*[local-name()='RetDataSet']/*[local-name()='NewDataSet']/*[local-name()='dtClients']");
    IXMLDOMNode newRow;

    foreach (XmlNode node in projectListXMLNode.ChildNodes)
    {
    newRow = dtClientsDataSourceNode.cloneNode(true);
    newRow.selectSingleNode("Name").text =
    node.FirstChild.InnerText;
    getProjectsForClientDataSource.DOM.insertBefore(newRow,
    dtClientsDataSourceNode);
    }

    I've put debug code, and the last statement in the foreach loop is not working. I don't get any errors, but my Project drop-down listbox isn't being filled with my list of values.


    quote:
    Originally posted by Alex Getman

    I found the solution! :P

    The point is that Infopath Document heavy relies at it's internal xml structure. In code that was provided above I am calling

    documentRoot.appendChild(newRow);

    That works fine if I got only one DataSource of type group inside main Infopath document datasource, but when another datasource was added an exception was trown because it's name was differ from first one.

    So to fill more than one DataSources inside Infopath document, you should use something like:

    documentRoot.insertBefore(newRow, jobRolesList);

    where jobRolesList is the last added DataSource.

    Also you should always keep in mind that all C# code manipulations with Infopath DataSources will hardly depends on it's internal xml structure (xsd schema actually)


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