How to sort the RadComboBoxItems Alphabetically?

5 posts, 0 answers
  1. Vinnarasi
    Vinnarasi avatar
    14 posts
    Member since:
    Aug 2013

    Posted 01 Oct 2013 Link to this post

       Items listed in the RadComboBox need to be sorted Alphabetically.
       How to Alphabetically sort the RadComboBoxItems?

    With Thanks,

  2. Kalin
    Kalin avatar
    1284 posts

    Posted 03 Oct 2013 Link to this post

    Hi Vinnarasi,

    In order to sort the items in the ComboBox you would only need to sort the collection bound to the ComboBox ItemsSource in the code behind. For example if this is your ViewModel:

    public ObservableCollection<string> Items { get; set; }
    public ViewModel()
        this.Items = new ObservableCollection<string>

    You have to sort it in the code behind as follows:

    public MainWindow()
        this.DataContext = new ViewModel();
        var viewModel = this.DataContext as ViewModel;
        viewModel.Items = new ObservableCollection<string>(viewModel.Items.OrderBy(x => x));

    Hope this will help you.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. Matthias
    Matthias avatar
    1 posts
    Member since:
    Jan 2012

    Posted 11 Mar 2015 in reply to Kalin Link to this post

    Hi Kalin,
    I have a similar problem. The difference is that I use a converter for my display value, like this:

                                                <TextBlock Text="{Binding Id, Converter={StaticResource LabelTypeToNameConverter}}"/>

    I want to sort by the displayed value, i.e. by the result of the converter. How can I achieve this?

    Kind regards


  4. Kalin
    Kalin avatar
    1284 posts

    Posted 12 Mar 2015 Link to this post

    Hi Matthias,

    You can bind the SelectedItem to a property in the ViewModel in order to reorder the collection once the selection is changed. However if this doesn't help - please provide some more information and sample of the exact scenario.

    Hope this will work for you.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  5. Alan
    Alan avatar
    1 posts
    Member since:
    Apr 2012

    Posted 28 Oct 2015 Link to this post

    One also can use CollectionViewSource.  However, this can be slow if there is a large quantity of items.

    Here is how I did it for a collection of strings to be sorted alphabetically by string.

    In VB.NET data context:

        ReadOnly Property MyTags As ObservableCollection(Of String)

    In XAML:

    <UserControl x:Class="MyTagUC"
            <CollectionViewSource x:Key="MyTagCollectionViewSource" Source="{Binding Path=MyTags}" >
                    <scm:SortDescription />
        <telerik:RadComboBox x:Name="cmbMyTag" ItemsSource="{Binding Source={StaticResource MyTagCollectionViewSource}}" SelectedItem="{Binding SelectedMyTag}" />

    Here is how I did it for a collection of objects to be sorted by alphabetically by a string property on an interface implemented by the class of the objects.

    In VB.NET data context:

        Public Interface IMyEntity
            ReadOnly Property MyName As String
        End Interface

        ReadOnly Property MyEntities As ObservableCollection(Of IMyEntity)

    In XAML:

            <CollectionViewSource x:Key="MyEntityCollectionViewSource" Source="{Binding Path=MyEntities}" >
                    <scm:SortDescription PropertyName="MyName" />
        <telerik:RadComboBox x:Name="cmbMyEntity" DisplayMemberPath="MyName" ItemsSource="{Binding Source={StaticResource MyEntityCollectionViewSource}}" SelectedItem="{Binding SelectedMyEntity}" />
Back to Top