Sorting Gridview according to combination of 3 hidden column.

2 posts, 0 answers
  1. Jayesh V
    Jayesh V avatar
    2 posts
    Member since:
    Apr 2010

    Posted 02 Sep 2011 Link to this post

    We are creating a winform application.
    We are binding radgridview with auto generated columns. so we have a IList<PClass> for binding radGridview with columns Id(int), Year(int), dept (Char), DeptNumber (autoincrement int for each dept), ProposalId(Combination of year/OF/deptChar/DeptNumber as string), Name(string), date(date without time).
    In radGridview id, year, dept and DeptNumber is hidden, and other is visible.
    so my problem is, when I click to ProposalId column header to sort that column, I want to actually sort with combination of year, dept and deptNumber column wise.
    here by default
           year => descending
           DeptChar => ascending
           DeptNumber => descending

    but when i click it  toggle the sort
    so how can we sort with this situation?

    thanks in advance,

    Jayesh Varu.
  2. Julian Benkov
    Julian Benkov avatar
    1135 posts

    Posted 07 Sep 2011 Link to this post

    Hello Jayesh V,

    You can handle the SortChanged event to achieve this functionality. Here is a simple code snippet which uses the AdventureWorks database:

    void radGridView1_SortChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)
        using (this.radGridView1.DeferRefresh())
            string[] defaultSorting = { "RevisionNumber", "OrderDate" };
            ListSortDirection[] defaultOrder = { ListSortDirection.Descending, ListSortDirection.Ascending };
            for (int i = 0; i < defaultSorting.Length; i++)
                int index = this.radGridView1.SortDescriptors.IndexOf(defaultSorting[i]);
                if (index >= 0)
            for (int i = defaultSorting.Length - 1; i >= 0; i--)
                this.radGridView1.SortDescriptors.Insert(0, new SortDescriptor(defaultSorting[i], defaultOrder[i]));

    I hope this helps. Do not hesitate to contact us if you have further questions.

    Julian Benkov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top