Version

WinGanttView Sorting

The WinGanttView™ control allows sorting of single and multiple task fields in the grid section of the control. Tasks can be sorted on multiple field criteria through the user interface by shift+clicking on the column headers in the grid area of the control. Sorting can also be done through code by adding task fields to the SortedFields collection. You can also perform custom sorting using the Comparer property.

Note
Note

Sorting is not supported for all Task properties; for example, sorting on the Dependencies collection is not supported.

The following example code assumes that you have an UltraGanttView control dropped onto your form that displays tasks and task details.

In Visual Basic:

Me.ultraCalendarInfo1.Tasks.SortedFields.Add(SortableTaskField.Name, SortOrder.Ascending)
Me.ultraCalendarInfo1.Tasks.SortedFields.Add(SortableTaskField.Duration, SortOrder.Descending)
Me.ultraCalendarInfo1.Tasks.SortedFields.Add
(SortableTaskField.PercentComplete, SortOrder.Descending)

In C#:

this.ultraCalendarInfo1.Tasks.SortedFields.Add(SortableTaskField.Name, SortOrder.Ascending);
this.ultraCalendarInfo1.Tasks.SortedFields.Add(SortableTaskField.Duration, SortOrder.Descending);
this.ultraCalendarInfo1.Tasks.SortedFields.
Add(SortableTaskField.PercentComplete, SortOrder.Descending);

Custom Sorting

In Visual Basic:

' Custom Sorting
Me.ultraGanttView1.CalendarInfo.Tasks.SortedFields.Comparer = New MySortComparer ()
Public Class MySortComparer
    Implements System.Collections.Generic.IComparer(Of Task)
    #Region "IComparer Members"
    Public Function Compare(ByVal x As Task, ByVal y As Task) As Integer
        Dim xTask As Task = DirectCast(x, Task)
        Dim yTask As Task = DirectCast(y, Task)
        'TODO: Logic to compare Task Fields. e.g:
         Return xTask.Deadline.CompareTo(yTask.Deadline)
    End Function
    #End Region "IComparer Members"
End Class

In C#:

// Custom Sorting
this.ultraGanttView1.CalendarInfo.Tasks.SortedFields.Comparer = new MySortComparer();
public class MySortComparer : System.Collections.Generic.IComparer<Task>
    {
        #region IComparer Members
        public int Compare(Task x, Task y)
        {
            Task xTask = (Task)x;
            Task yTask = (Task)y;
            //TODO:  Logic to compare Task Fields. e.g:
            return xTask.Deadline.CompareTo(yTask.Deadline);
        }
        #endregion IComparer Members
    }