How to sort a ResourceSet in C #

I have a resource file called filetypes.resx. Some of how I decided to associate resource values ​​with a drop-down list, but I don’t know how to sort ResourceSet values .

Here is what I have done so far,

FileTypes.resx

  • Name, Value
  • A, 1

  • IN 2

  • C, 3

code for binding dropdown list


DropDownList1.DataSource = Resources.FileTypes.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);
DropDownList1.DataTextField = "Key";
DropDownList1.DataValueField = "Value";
DropDownList1.DataBind();

Result

 A
 C
 B
As you can see the result is not sorted. Please help me to solve this issue.

Thank you very much in advance:)

+1
source share
4 answers

There is an IDictionaryEnumerator in the ressource set, so I think its elements are of type DictionaryEntry, try sorting the data source as follows:

DropDownList1.DataSource = Resources.FileTypes.ResourceManager
    .GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true)
    .OfType<DictionaryEntry>()
    .OrderBy(i => i.Value);

, , , :)

+7

ResourceSet Table, HashTable. , ( LINQ), DropDownList1.DataSource.

+1

Hashtable is not a sorted collection.

0
source

Hashtable tbl = Resources.FileTypes.ResourceManager.
GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true).Table;
List source = new List(tbl.Values);
source.Sort();
DropDownList1.DataSource = source;
DropDownList1.DataBind();

0
source

Source: https://habr.com/ru/post/1612272/


All Articles