Sort text based on Multi-select choices - InfoPath Dev
in

InfoPath Dev

Sort text based on Multi-select choices

Last post 11-26-2012 07:53 AM by dmbach. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 11-20-2012 09:28 AM

    • dmbach
    • Not Ranked
    • Joined on 11-20-2012
    • Posts 4

    Sort text based on Multi-select choices

    I have an InfoPath 2007 form with a multi-select list box control. I'm using the following code to capture the selections made by the user into a text field:

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    public void CSI_Announcement_Target_Changed(object sender, XmlEventArgs e)
    {
    XPathNavigator root = MainDataSource.CreateNavigator();
    XPathNodeIterator iter = root.Select("//my:CSI_Announcement_Target",
    NamespaceManager);
    System.Text.
    StringBuilder sb = new System.Text.StringBuilder();
    while (iter.MoveNext())
    {
    string value = iter.Current.Value;
    sb.Append(value);
    sb.Append(
    "; ");
    }
    root.SelectSingleNode(
    "//my:CSI_Announcement_Concat",
    NamespaceManager).SetValue(sb.ToString());
    }

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    I'd like the selected values to sort alphabetically, but they're currently sorted in the order in which they are selected (because of the Append coding). I'm not too familiar with writing C# code. I found this code online. It seems logical that there would be a way to do this, but I've not had any luck finding anything that works. I've tried populating a repeating table and sorting the rows, but I couldn't get that to work. I also found something about using workflows, but my experience with workflows is that they're temperamental. Is there anyone out there that is familiar enough with C# coding that they could maybe revise the above code so it will sort alphabetically as selections are made? Or is there a set of rules I could use to get the values to sort before submitting?

    Thank you!

  • 11-24-2012 10:56 AM In reply to

    Re: Sort text based on Multi-select choices

    Hi DMBach and welcome,

    I don't recommend the code you attached because it concatenates the values. Certainly, you don't need it since you can just use an InfoPath rule and eval(eval(concat(...))) to do the same thing without code.

    What I do recommend is to insert the values into a separate "selected" table and then sort that table.

    Qdabra (sponsor for this site) has a common library called qRules which supports both insert and sort (and over 120 other functions that could help you). I recommend installing a trial of that and looking at all of the online documentation and detailed user guide. It's very inexpensive too - probably the equivalent of 4-5 hours of your time but will save you hundreds of hours and you get our time too.

    Another idea: InfoPath 2003 has a sample called Asset Tracker with built in sort functionality. It's written in javascript though, but you could probably easily port it to VB or C# .NET. Still, it would probably take you 5-10 hours and you still wouldn't have insert.

    Yet another idea: there are hundreds of posts in this forum that have coding snippets in them. You could search for insert and sort and probably find some code samples.

    Whatever path you take, may you have a delightful journey,

    P

    Patrick Halstead
    Project Manager at Qdabra
  • 11-26-2012 07:53 AM In reply to

    • dmbach
    • Not Ranked
    • Joined on 11-20-2012
    • Posts 4

    Re: Sort text based on Multi-select choices

    Thanks, Patrick. Unfortunately, this form is for my employer, and they don't allow downloading any software. So, Qdabra is out of scope. But I will try the searches you suggested. I appreciate your help! :7)

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