Home Forums WinForms controls Xceed Grid for WinForms Secondary Sub-sort

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14981 |

    Lets say I have a grid that displays employee information with the followig columns:

    id, division, position, last name, first name, position, start date

    Each column is sortable. However I would like to define a set a rules in the sorting, such that if the value of 2 records in a column are equal, the grid sub-sorts on other columns.

    In other words if the user clicks on the division column header, all the employees in the ‘sales’ division, are sub sorted by position and then by last name.

    I cannot seem to use a DataComparer on the column, as the IComparer only gets passed the value in the column without reference to the row or record required to perform a more complex sort.

    Any tips on how to accomplish this type of sorting would be appreciated.

    Thanks

    Imported from legacy forums. Posted by Doug (had 2494 views)

    User (Old forums)
    Member
    Post count: 23064

    Please note: I am aware of grouping, but for a number of reasons would prefer to avoid using groups.

    Imported from legacy forums. Posted by Doug (had 356 views)

    User (Old forums)
    Member
    Post count: 23064

    You can add a regular sort on each column you want once the user sorts one of the columns. For example, once the user sorts “division”, in the event handler, add a sort on “position” and then on “last name”.

    e.g.:
    <i>
    private void Form1_Load(object sender, System.EventArgs e)
    {
    gridControl1.Columns[ “division” ].SortDirectionChanged += new EventHandler(division_SortDirectionChanged);
    }

    private void division_SortDirectionChanged(object sender, EventArgs e)
    {
    gridControl1.Columns[ “position” ].SortDirection = SortDirection.Ascending;
    gridControl1.Columns[ “last name” ].SortDirection = SortDirection.Ascending;
    }
    </i>

    Imported from legacy forums. Posted by André (had 3361 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.