Search
Grouping

Views that support grouping: Timetable / Week Range / List / Resource. The Resource view can only operate when grouping is enabled. The other views do not support grouping.

In order to enable grouping the following steps should be done:

The following code illustrates how to enable grouping by contacts:

C#  Copy Code

// Define two contacts to group by
Contact c1 = new Contact();
c1.FirstName = "John";

Contact c2 = new Contact();
c2.FirstName = "Jack";

// Add the contacts to the schedule
calendar.Schedule.Contacts.Add(c1);
calendar.Schedule.Contacts.Add(c2);

// Select these contacts for grouping by adding them to
// the appropriate Calendar collection
calendar.Contacts.Add(c1);
calendar.Contacts.Add(c2);

// Enable grouping by contacts
calendar.GroupType = GroupType.GroupByContacts;

Visual Basic  Copy Code

' Define two contacts to group by
Dim c1 As New Contact()
c1.FirstName = "John"

Dim c2 As New Contact()
c2.FirstName = "Jack"

' Add the contacts to the schedule
calendar.Schedule.Contacts.Add(c1)
calendar.Schedule.Contacts.Add(c2)

' Select these contacts for grouping by adding them to
' the appropriate Calendar collection
calendar.Contacts.Add(c1)
calendar.Contacts.Add(c2)

' Enable grouping by contacts
calendar.GroupType = GroupType.GroupByContacts

The text displayed in the header of the corresponding resource depends on the type of the resource and is as follows:

Grouping and Appearance

  • In resource view a single row is dedicated to each individual resource. The row has a header, displaying the text for that resource and contains all items, associated with that resource for the specified time interval. The row can be additionally subdivided to lanes depending on the ResourceViewSettings.ViewStyle.
  • In timetable view each column (or row in a horizontal view) that represents a day is additionally subdivided to the number of grouped resources. For example if there are 3 resources selected to group by, each day column in the view is subdivided to 3 columns. The sub-columns represent individual resources and contain only the items specific for them. The sub-columns have headers containing the resource text. The header of the day column is displayed above the headers of its underlying resource columns.
  • The week range view displays a separate view for grouped resources. For example if there are two resources, two views are displayed alongside, each of which contains the items associated with its corresponding resource.

Multiple Grouping

The Resource view allows grouping by two resource types simultaneously. The primary resource type is still specified through the GroupType property. The secondary resource type is specified through the SecondaryGroupType property. When multiple grouping is enabled the view is divided by the primary resources first. Then each primary resource is additionally subdivided by all secondary resources. For example, if there are two primary resources and three secondary resources specified, the view will display two main headers, divided by three subheaders each, for a total of six rows.

Custom Grouping

Usually the GroupType and SecondaryGroupType properties are set to different values. For example, GroupType can be set to GroupByContacts and SecondaryGroupType can be set to GroupByResources, to group by contacts and resources respectively. However, it is possible to group resources by their runtime type. In this case both the primary and the secondary resources need to be placed in the Calendar.Resources collection and both GroupType and SecondaryGroupType need to be set to GroupByResources. In addition, CustomGroupType and CustomSecondaryGroupType must be set to the appropriate runtime type of the resources. The following example illustrates how to enable grouping by custom resources of type Machine and Worker:

C#  Copy Code

calendar.GroupType = GroupType.GroupByResources;
calendar.SecondaryGroupType = GroupType.GroupByResources;
calendar.CustomGroupType = typeof(Machine);
calendar.CustomSecondaryGroupType = typeof(Worker);

Visual Basic  Copy Code

calendar.GroupType = GroupType.GroupByResources
calendar.SecondaryGroupType = GroupType.GroupByResources
calendar.CustomGroupType = GetType(Machine)
calendar.CustomSecondaryGroupType = GetType(Worker)

It might not always be desired that a primary resource is associated with all secondary resources. In the above case for example, only a subset of the workers could be associated with a machine. This can achieved in MindFusion.Scheduling through the CustomizeGrouping event. Let us assume that the Machine class provides a list of workers that are qualified to work with that machine. In this case, the following CustomizeGrouping event handler enables grouping only by the qualified workers:

C#  Copy Code

private void OnCustomizeGrouping(object sender, CustomizeGroupingEventArgs e)
{
    Machine machine = e.Parents[0] as Machine;
    e.GroupByResources.Clear();
    foreach (Worker worker in machine.QualifiedWorkers)
        e.GroupByResources.Add(worker);
}

Visual Basic  Copy Code

Private Sub OnCustomizeGrouping(ByVal sender As Object, ByVal e As CustomizeGroupingEventArgs)

    Dim machine As Machine = TryCast(e.Parents(0), Machine)
    e.GroupByResources.Clear()
    For Each worker As Worker In machine.QualifiedWorkers
        e.GroupByResources.Add(worker)
    Next

End Sub