Sorting by DateTime

2 posts, 0 answers
  1. Matt
    Matt avatar
    15 posts
    Member since:
    Jan 2009

    Posted 15 May 2012 Link to this post


    Has anyone managed to sort a listview by a date rather than having the column taken to be a string?

    I can't see a date specific entry so i'm currently using

    ShareMessageListView.Columns.Add(new Telerik.WinControls.UI.ListViewDetailColumn("Date"));

    This may be my problem.
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 17 May 2012 Link to this post

    Hi Mat,

    Thank you for contacting us.

    Currently, RadListView does not support typed columns but it should sort the values according to their types and without taking them as strings. This might depend on the way you populate your list view with data. Your DateTime values might somehow get cast to string while populating the list view. The following code sample demonstrates how to add values to RadListView in order to be able to sort according to the DateTime values:
    public Form1()
    {
        InitializeComponent();
     
        this.radListView1.ViewType = Telerik.WinControls.UI.ListViewType.DetailsView;
        this.radListView1.EnableColumnSort = true;
        this.radListView1.EnableSorting = true;
     
        for (int i = 0; i < 30; i++)
        {
            this.radListView1.Items.Add("asdf" + i, DateTime.Now.AddHours(i), "col 3", DateTime.Now.AddDays(i));
        }
    }

    I hope this will help you. If you continue experiencing difficulties, please send me a code snippet which demonstrates the way you setup the RadListView. This will help me provide you with a proper solution.

    Kind regards,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top