locked
OrderBy without OrderedEnumerable RRS feed

  • Question

  • Hello, I bind WPF's ComboBox to

     

    from c in CultureInfo.GetCultures(CultureTypes.NeutralCultures)

    where c != CultureInfo.InvariantCulture

    orderby c.DisplayName

    select c;

     

    But this returns OrderedEnumerable<CultureInfo, string> and the ComboBox chooses to display strings (resulting the DataTemplate for CultureInfo to be ignored).

     

    Is there any way how to get just IEnumerable<CultureInfo> yet still ordered?

     

    Or, is there any member of OrderedEnumerable or any of its ancestors to which I could the ComboBox bind to?

     

           Thanks, Jan

    Sunday, August 12, 2007 7:59 PM

Answers

  • Add ToList or ToArray to the end of your query, i.e.:


    (from c in CultureInfo.GetCultures(CultureTypes.NeutralCultures)

    where c != CultureInfo.InvariantCulture

    orderby c.DisplayName

    select c).ToList()


    or:

    (from c in CultureInfo.GetCultures(CultureTypes.NeutralCultures)

    where c != CultureInfo.InvariantCulture

    orderby c.DisplayName

    select c).ToArray()



    This will give you an ordinary List<CultureInfo> or CultureInfo[].

    Regards

    Joe
    Monday, August 13, 2007 8:39 AM