The reason for this is that when the query provider is LINQ to Objects the GroupBy is executed over the converted values. I will see whether I can implement sorting of the raw distinct values according to their converted string values out-of-the-box and let you know about my findings.
You have to have in mind though that if different distinct values map to one and the same converted value you will still see this string value several times, because the Distinct operation is performed on the raw data and not on the converted values. Here is a practical example:
If you have these distinct values: 1, 2, 3 and they are converted by an IValueConverter to "Odd", "Even", "Odd" you will see this in the distinct values list:
because the actual raw distinct values that sit behind these string are still 1, 2, 3 and they are different. This is by design and cannot be changed for the reasons I have explained before. The Data Engine can only work with data values -- it cannot work with UI-specific values which might be localized and so forth.
But I guess that your case with the states will not be such and you will not have repeating distinct values.
Now, until I try to find a solution for the sorting I can suggest two very easy solutions in case you are binding the grid to an in-memory collection.
A. Use FilterMemberPath.
1. Create a new read-only property on your business object that will return "Swtizerland" for the CH instance and Algeria for the DZ instance, i.e. you get the point. You may call it CountryName.
2. Then set your column's FilterMemberPath to be CountryName and there you go -- your column will still be bound to the Country property, but it will be filtered on the CountryName property.
I have prepared a sample project demonstrating this approach.
B. Order the distinct values in the event handler like this:
sender, Telerik.Windows.Controls.GridView.GridViewDistinctValuesLoadingEventArgs e)
var countryCodes = ((RadGridView)sender).GetDistinctValues(e.Column,
e.ItemsSource = countryCodes.Cast<
>().OrderBy(countryCode => Country.GetCountryName(countryCode));
I have attached a second sample project for this approach as well.
I hope that one of these two approaches will meet your requirements.
I hope this helps.
All the best,
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>