How to set default value in dropdown box by code. - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

How to set default value in dropdown box by code.

Last post 02-08-2010 06:41 AM by gombear. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 02-05-2010 01:25 PM

    How to set default value in dropdown box by code.

    I'm getting error/exception from setting default value for dropdown list. 

     Here is what I'm doing.......

    I have a dropdown box that is populated from repeating node values in the form.

    //***This is to create values for the repeating node.

    string myNameSpace = NamespaceManager.LookupNamespace("my");

    try{

    Action[] xxCodes = DAO.GetValues("some");for (int i = 0; i < xxCodes.Length; i++)

    {

    XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:SomeGroup", NamespaceManager).AppendChild();

    writer.WriteStartElement("SomeGroups", myNameSpace);

    writer.WriteElementString("someValue", myNameSpace, xxCodes[i].Code);

    writer.WriteElementString("someDisplayName", myNameSpace, xxCodes[i].Description);

    writer.WriteEndElement();

    writer.Close();

    }

    ......

    //Then I map the dropdown list box to this repeating node.  dropdown list works fine

    So far so good. 

    //

    Now I want depend on the other value, I want to pre-select the value for this dropdown list.  So this pre-selected value will display as default value, but users can still change it by clicking dropdown selection button.

    //Here is a snippet of code to set default display. 

    XPathNavigator navigator = this.CreateNavigator();

    navigator.SelectSingleNode("/my:myFields/my:dropdownlist").Setvalue("defaultValue");

    //Then this line of code produce this exception

    >System.Xml.XPath.XPathException: Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.

    How do I fix this?  Or What is the proper code to set default value for dropdown list?

    Thanks.

  • 02-05-2010 08:38 PM In reply to

    Re: How to set default value in dropdown box by code.

    You need to pass the NamespaceManager to SelectSingleNode().  You're already doing that correctly in this line:

     XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:SomeGroup", NamespaceManager).AppendChild();

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-08-2010 06:41 AM In reply to

    Re: How to set default value in dropdown box by code.

    Oh, my.

    I'm must having senior moment.   Thank a lot.

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