empty entries in drop down list - InfoPath Dev
in

InfoPath Dev

empty entries in drop down list

Last post 12-02-2008 10:51 PM by Shiva. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 11-27-2008 04:42 AM

    empty entries in drop down list

    main data sourceHello there, I'm populating a List through code. I get the entries for the dropdown from a sharepoint list which has a lookup. The list holds informations about articles and has a lookup the specific colors for each article. Through the lookup I get a String for the colors which looks like this: "2;#red;#12;#blue". number and name are one line in the list i.e.

    articlenumber: 2 name: red

    articlenumber 12 name: blue

    I hope you can imagine.

     

    I create entries for each color-value pair in my main data source.  On the left side you see an image of my main data source. The color-value pairs are located in:

    myFields/Bestellungen/Bestellung/ddArtikel/artikel/ddFarben/ddFarbe

    The nodenames are: ddFarbeNr <- for the number, ddFarbeText <- for the name of the color

    I create xml strings for every color and add them to ddFarben, right before the string (i.e.: 2;#red;#12;#blue) is splitted and "#" are removed. The split is saved into aFarben.

    for (int i = 0; i < aFarben.Length; i++)

    {

    if (i % 2 == 1)

    {

    String sDDFarben = "<my:ddFarbe><my:ddFarbeNr>"+ aFarben[i-1] +"</my:ddFarbeNr>"+

    "<my:ddFarbeText>"+ aFarben[i] +"</my:ddFarbeText></my:ddFarbe>";

    xnFarben.SelectSingleNode("../my:ddFarben", NamespaceManager).AppendChild(sDDFarben);

    }

    }

     I added color values for different articles in the sharepoint list. One article shows everything correct. The other ones have empty entries before and/or after the color entries. Which I didn't add. The xml string has exact the right values inside. How can it be that there are empty line in the dropdown ?

     

    Thanks in advance.

    Regards Matthias

  • 11-27-2008 05:53 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: empty entries in drop down list

    Hello,

    Where you are getting empty entries in your dropdown list? If it is in starting then you have to change the code as below before adding the nodes.

    Delete all child nodes for below node,

    XmlNode ddFarbenNode = xnFarben.SelectSingleNode("../my:ddFarben", NamespaceManager);

    ddFarbenNode. RemoveAll();

    If the blank entries in the middle then you have to check code in your for loop. You might be adding some empty nodes to ddFarbenNode.

  • 11-27-2008 07:00 AM In reply to

    Re: empty entries in drop down list

    The function you postet does not work. SelectSingleNode has a return value an XPathNavigator object. Here are some images to show what I mean. One entry is correct and the other ones are not. I don't know why. They all use the same functions.

    drag drop list middle correct

     Drag drop list correct

     

     

     

     

     

     

     

     

     

    drag drop top correct

     Before adding the values I always delete all the nodes inside the ddFarben node. Here is my code:

    public void Artikelnummer_Changed(object sender, XmlEventArgs e)

    {

    try

    {

    XPathNavigator xnFarben = e.Site.SelectSingleNode("..//my:tempFarbe[../my:ddArtikelnummer = ../../../my:Artikelnummer]", NamespaceManager);

    MessageBox.Show(xnFarben.InnerXml);

    String sFarben = xnFarben.InnerXml;

     

    sFarben = sFarben.Replace(
    "#","");

    char[] split = {';'};

    String[] aFarben = sFarben.Split(split);

     

    List<XPathNavigator> nodesToDelete = new List<XPathNavigator>();

     

    foreach (XPathNavigator option in xnFarben.Select("..//my:ddFarbe", NamespaceManager))

    {

    nodesToDelete.Add(option);

    }

     

    //delete all nodes on the list

    foreach (XPathNavigator option in nodesToDelete)

    {

    option.DeleteSelf();

    }

     

    for (int i = 0; i < aFarben.Length; i++)

    {

    if (i % 2 == 1)

    {

    String sDDFarben = "<my:ddFarbe><my:ddFarbeNr>"+ aFarben[i-1] +"</my:ddFarbeNr>"+

    "<my:ddFarbeText>"+ aFarben[i] +"</my:ddFarbeText></my:ddFarbe>";

    xnFarben.SelectSingleNode("../my:ddFarben", NamespaceManager).AppendChild(sDDFarben);

    }

    }

    }

    catch(Exception ex)

    {

    MessageBox.Show("Message:\n" + ex.Message + "\nDetail:\n" + "\nStackTrace\n" + ex.StackTrace);

    }

    }

    I don't know why it is different for the articles. Maybe it has something to do with the Sharepoint lookup. I don't know. When I retrieve the xml currently used there is everything allright, but anyhow there are these empty lines.

  • 11-28-2008 10:58 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: empty entries in drop down list

    Hello,

    You have to debug for below line,

    xnFarben.SelectSingleNode("../my:ddFarben", NamespaceManager).AppendChild(sDDFarben);

    In this ‘sDDFarben' node is empty for some times. For every node adding in your for loop, you have to check the ‘sDDFarben' node contains value or not.

    Hope this helps you.

  • 12-01-2008 12:43 AM In reply to

    Re: empty entries in drop down list

    Hello Shiva, thank you for your advice. I have testet it and the String always contains the correct values. Not more, not less. Any other ideas ?

  • 12-01-2008 04:26 AM In reply to

    Re: empty entries in drop down list

    I found the error. It was in another function. I was deleting the Nodes before and created new ones, maybe there were too much. Anyway it works correct now. Thank you for trying to help me Shiva.

  • 12-02-2008 10:51 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: empty entries in drop down list

    Hello,

    Thanks for letting us know. Glad to be of help :)

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