drop down list with Infopath 2007 - InfoPath Dev
in

InfoPath Dev

drop down list with Infopath 2007

Last post 11-23-2008 09:07 PM by Anuma. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 11-21-2008 06:49 AM

    drop down list with Infopath 2007

      Hi,

     I have created a datatable and  wanted to map one of the field with dropdown list in Infopath 2007. But it is not populating, Pls review the code and correct me .....

    Full source code

    using Microsoft.Office.InfoPath;

    using System;

    using System.Xml;

    using System.Xml.XPath;

    using System.Collections;

    using Microsoft.Office.Interop.InfoPath.SemiTrust;

    using System.Data;

    namespace sojutest

    {

    public partial class FormCode

    {

    public XDocument thisXDocument;

    // Member variables are not supported in browser-enabled forms.

    // Instead, write and read these values from the FormState

    // dictionary using code such as the following:

    //

    // private object _memberVariable

    // {

    // get

    // {

    // return FormState["_memberVariable"];

    // }

    // set

    // {

    // FormState["_memberVariable"] = value;

    // }

    // }

    // NOTE: The following procedure is required by Microsoft Office InfoPath.

    // It can be modified using Microsoft Office InfoPath.

    public void InternalStartup()

    {

    EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);

    }

    public void FormEvents_Loading(object sender, LoadingEventArgs e)

    {

    ArrayList sortValues = new ArrayList();

    XPathNavigator xnDoc = this.MainDataSource.CreateNavigator();

    XPathNavigator xnStatus = xnDoc.SelectSingleNode("/my:myFields/my:field1", this.NamespaceManager);

    xnStatus.SetValue("test");

    // IXMLDOMNodeList DropDownValueNodeList = thisXDocument.DOM.selectNodes("/my:myFields/my:field2");

    //foreach (IXMLDOMNode DropDownValueNode in DropDownValueNodeList)

    //{

    // sortValues.Add(thisXDocument.DOM.selectSingleNode("").text);

    //}

    //sortValues.Sort();

    DataTable table = new DataTable();

    //Create 7 columns for this DataTable

     

    DataColumn col1 = new DataColumn("ID");

    DataColumn col2 = new DataColumn("Name");

    DataColumn col3 = new DataColumn("Checked");

    DataColumn col4 = new DataColumn("Description");

    DataColumn col5 = new DataColumn("Price");

    DataColumn col6 = new DataColumn("Brand");

    DataColumn col7 = new DataColumn("Remarks");

    //Define DataType of the Columns

    //col1.DataType = System.Type.GetType("System.Int");

    //col2.DataType = System.Type.GetType("System.String");

    //col3.DataType = System.Type.GetType("System.Boolean");

    //col4.DataType = System.Type.GetType("System.String");

    //col5.DataType = System.Type.GetType("System.Double");

    //col6.DataType = System.Type.GetType("System.String");

    //col7.DataType = System.Type.GetType("System.String");

    //Add All These Columns into DataTable table

    table.Columns.Add(col1);

    table.Columns.Add(col2);

    table.Columns.Add(col3);

    table.Columns.Add(col4);

    table.Columns.Add(col5);

    table.Columns.Add(col6);

    table.Columns.Add(col7);

    //Create a Row in the DataTable table

    DataRow row = table.NewRow();

    //Fill All Columns with Data

    row[col1] = "1100";

    row[col2] = "Computer Set";

    row[col3] = true;

    row[col4] = "New computer set";

    row[col5] = 32000.00;

    row[col6] = "NEW BRAND-1100";

    row[col7] = "Purchased on July 30,2008";

    //Add the Row into DataTable

    table.Rows.Add(row);

    DataRow row1 = table.NewRow();

    row1[col1] = "1100";

    row1[col2] = "Computer Set";

    row1[col3] = true;

    row1[col4] = "New computer set";

    row1[col5] = 32000.00;

    row1[col6] = "NEW BRAND-1100";

    row1[col7] = "Purchased on July 30,2008";

    table.Rows.Add(row1);

    XPathNavigator xnStatus1 = xnDoc.SelectSingleNode("/my:myFields/my:field4", this.NamespaceManager);

    xnStatus1.SetValue("");

    XPathNavigator templateNode = xnStatus1.Clone();

    foreach (DataRow dr in table.Rows)

    {

    XPathNavigator newNode = templateNode.Clone();

    string value = dr[0].ToString();

    newNode.SetValue(value);

    xnStatus.SetValue(dr[0].ToString());

    xnStatus1.SetValue(dr[0].ToString());

    xnStatus1.InsertAfter();

    xnStatus1.InsertBefore();

    }

    }

    }

    }

     

    Thanks

    Soju

  • 11-21-2008 07:34 AM In reply to

    Re: drop down list with Infopath 2007

    Pls help ............
  • 11-21-2008 07:40 AM In reply to

    Re: drop down list with Infopath 2007

    Are you trying to populate the dropdown with information from the database or are you trying to write the information from the dropdown into the database?

    Fishman
  • 11-21-2008 08:05 AM In reply to

    Re: drop down list with Infopath 2007

    I have created a c# datatable. I need to populate the dropdown with information from the database, because it a demo project and future I need to populate from database and sharepoint list.

    With help of setvalue property I have populated in text box.

    Thanks

    Soju

     

  • 11-21-2008 08:28 AM In reply to

    Re: drop down list with Infopath 2007

    First, you have to create a data connection to whatever source that you want to use to populate the dropdown.  In design mode, go to tools -> data connections -> add. 

    Select 'recieve' and click next. 

    Select the type of data source that you are connecting to.  Click next.

    Continue on with the wizard until you have set up your connection.

    Doubl click your dropdown.

    Select 'look up values from an external data source'

    Select your data source from the dropdown.

    Select your entries.

    If you need to, specify your field/values.

    Click OK and preview your form.

    Fishman
  • 11-21-2008 07:57 PM In reply to

    Re: drop down list with Infopath 2007

    Yes correct. The InfoPath page having lot of complicated cascading. So i wanted to populate certain values and wanted to sort dropdown items.

    Do you know how to sort dropdown list items

    Thanks

     

  • 11-22-2008 06:03 AM In reply to

    Re: drop down list with Infopath 2007

    You will have to sort the entries at the data source.  Just arrange the data in the table the way that you want to see it in the dropdown.  If you want to limit the items that show up in the dropdown, you can apply filters to acccomplish that.  Double click the dropdown, click the xpath button for the entries, click the "filter data" button at the bottom of the dialog box and set up your filters there.

    Fishman
  • 11-23-2008 08:36 PM In reply to

    Re: drop down list with Infopath 2007

    Sorry I am not getting XPath button on InfoPath 2007. If I double click the dropdown button, I am getting property window.  Could you please little elaborate the above steps?

  • 11-23-2008 09:07 PM In reply to

    • Anuma
    • Top 25 Contributor
      Female
    • Joined on 07-20-2005
    • India
    • Posts 525

    Re: drop down list with Infopath 2007

    Hello,

     

    XPath button will be displayed if you select the second or third option under the “List Box Entries”. It will be displayed beside of the “Entries” text box.

     

    Anuma Chinthapalli /
    http://www.GGKTech.com
Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.