Skip to content

Latest commit

 

History

History
52 lines (38 loc) · 2.93 KB

File metadata and controls

52 lines (38 loc) · 2.93 KB

WinForms Scheduler - Sort resources

This example shows how to create a comparer to sort Scheduler resources based on a specific condition (in this example, the Resource.Caption and the number of resource appointments).

The example also demonstrates how to prevent sorting ("ResourceNOfAppointments" mode) for an "Unassigned" resource. This resource is always displayed first.

The SchedulerStorageBase.ResourceCollectionLoaded event is handled to automaticcally sort resources when the underlying collection changes:

private void schedulerStorage1_ResourceCollectionLoaded(object sender, System.EventArgs e) {
    ApplySorting();
}

private void ApplySorting() {
    IComparer<Resource> comparer = null;
    if (CurrentSortOrder == ResourcesSortOrder.Ascending)
        comparer = new ResourceCaptionComparer();
    else if (CurrentSortOrder == ResourcesSortOrder.Descending)
        comparer = new ResourceCaptionReverseComparer();
    else if (CurrentSortOrder == ResourcesSortOrder.NOfAppointments)
        comparer = new ResourceNOfAppointmentsComparer(schedulerStorage1);
    else
        return;
    schedulerStorage1.Resources.Items.Sort(comparer);
    schedulerControl1.ActiveView.LayoutChanged();
}

Files to Review

Documentation

Does This Example Address Your Development Requirements/Objectives?

(you will be redirected to DevExpress.com to submit your response)