Skip to content

Create a custom comparer to sort Scheduler resources based on a specific condition.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/winforms-scheduler-sort-resources

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)