I have an XML db field which I use to store the name of a country.
<countries>
<country lang="en">United States</country>
<country lang="es">Estados Unidos</country>
</countries>
I then have a ReadOnlyListBase class (CountryInfoList) which gets the field and based on the current language will get the correct value from the xml.
Since I cannot count on the DB to be able to order base on the selected language, I have to sort the list myself.
In the examples I've seen, the ordering is done in the GUI, however, I would like to hide that detail from the UI and just provide it an ordered list based on the selected language.
So is there a way to sort on the BOL?
Thank you!
- Andy
Thank you Brian, I ended up using the SortedBindingList to sort the list after I get it from the db:
Public Shared Function GetCountryInfoList(ByVal Language As String) As SortedBindingList(Of CountryInfo)
If (_Countries.Item(Language) Is Nothing) Then
Dim unSorted As CountryInfoList = DataPortal.Fetch(Of CountryInfoList)(New Language_Criteria(Language)) 'Get Unsorted List
Dim sorted As SortedBindingList(Of CountryInfo) = New SortedBindingList(Of CountryInfo)(unSorted)
sorted.ApplySort("Name", ComponentModel.ListSortDirection.Ascending)
_Countries.Item(Language) = sorted
End If
Return CType(_Countries.Item(Language), SortedBindingList(Of CountryInfo))
End Function
The only part I'm not too fond of is that I have to return SortedBindingList(Of CountryInfo). Ideally I would be returning a sorted CountryInfoList, but I'm not able to convert one to the other.
Is this possible?
- Andy
Andy,
One idea would be to create a 2nd instance of CountryInfoList using New and then loop over the sorted collection and add each object to your New instance.
Seems like a lot of trouble compared to the 1.x way of directly sorting the collection. But Rocky had said that the original method caused all kinds of problems.
Joe
Joe,
I tried your suggestion and it worked, but you are right, it is too much work :)
- Andy
Copyright (c) Marimer LLC