This example demonstrates how to create schedule groups, how to associate a group to appointments and how to apply grouping to schedule view modes. Each view mode (except for "Timeline") has a default date related grouping, so you can either add a new grouping or insert it before the default one. This will affect the order in which the groupings are applied. Use the radio button on the right to control the grouping order.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Schedule;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NGroupingExample";
// Create the NOV example and its controls
NWidget exampleContent = CreateExampleContent();
NWidget exampleControls = CreateExampleControls();
if (exampleControls != null)
{
exampleControls.PreferredWidth = 300;
}
// Place the example and its controls in a pair box
NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
pairBox.FillMode = ENStackFillMode.First;
pairBox.FitMode = ENStackFitMode.First;
pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);
// Host the example in the form
NNovWidgetHost host = new NNovWidgetHost(pairBox);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
#endregion
#region Example
public NWidget CreateExampleContent()
{
// Create a simple schedule
NScheduleViewWithRibbon scheduleViewWithRibbon = new NScheduleViewWithRibbon();
m_ScheduleView = scheduleViewWithRibbon.View;
m_ScheduleView.Document.PauseHistoryService();
try
{
InitSchedule(m_ScheduleView.Content);
}
finally
{
m_ScheduleView.Document.ResumeHistoryService();
}
// Return the commanding widget
return scheduleViewWithRibbon;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
stack.Add(new NRadioButton("Time grouping first"));
stack.Add(new NRadioButton("Group grouping first"));
NRadioButtonGroup groupingOrderGroup = new NRadioButtonGroup(stack);
groupingOrderGroup.SelectedIndexChanged += OnRadioGroupSelectedIndexChanged;
groupingOrderGroup.SelectedIndex = 0;
return groupingOrderGroup;
}
public string GetExampleDescription()
{
return @"
This example demonstrates how to create schedule groups, how to associate a group to appointments and
how to apply grouping to schedule view modes. Each view mode (except for ""Timeline"") has a default
date related grouping, so you can either add a new grouping or insert it before the default one. This
will affect the order in which the groupings are applied. Use the radio button on the right to control
the grouping order.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Schedule Grouping Appointments", "https://www.nevron.com/docs/openvision/schedule-grouping-appointments.html"),
("Schedule Grouping Overview", "https://www.nevron.com/docs/openvision/schedule-grouping-overview.html"),
("Schedule Appointments", "https://www.nevron.com/docs/openvision/schedule-appointments.html"),
("Schedule", "https://www.nevron.com/docs/openvision/schedule.html"),
};
}
#endregion
#region Implementation
private void InitSchedule(NSchedule schedule)
{
const string ActivityGroup = "Activity";
const string Work = "Work";
const string Rest = "Rest";
const string Travel = "Travel";
schedule.ViewMode = ENScheduleViewMode.Day;
// Add a schedule group
schedule.Groups.Add(new NScheduleGroup(ActivityGroup, new string[] { Work, Rest, Travel }));
// Add a grouping to each of the view modes
schedule.DayViewMode.Groupings.Add(new NGroupGrouping(ActivityGroup));
schedule.WeekViewMode.Groupings.Add(new NGroupGrouping(ActivityGroup));
schedule.MonthViewMode.Groupings.Add(new NGroupGrouping(ActivityGroup));
schedule.TimelineViewMode.Groupings.Add(new NGroupGrouping(ActivityGroup));
// Create the appointments
DateTime today = DateTime.Today;
schedule.Appointments.Add(CreateAppointment("Travel to Work", today.AddHours(6.5), today.AddHours(7.5), Travel));
schedule.Appointments.Add(CreateAppointment("Meeting with John", today.AddHours(8), today.AddHours(10), Work));
schedule.Appointments.Add(CreateAppointment("Conference", today.AddHours(10.5), today.AddHours(11.5), Work));
schedule.Appointments.Add(CreateAppointment("Lunch", today.AddHours(12), today.AddHours(14), Rest));
schedule.Appointments.Add(CreateAppointment("News Reading", today.AddHours(12.5), today.AddHours(13.5), Rest));
schedule.Appointments.Add(CreateAppointment("Video Presentation", today.AddHours(14.5), today.AddHours(15.5), Work));
schedule.Appointments.Add(CreateAppointment("Web Meeting", today.AddHours(16), today.AddHours(17), Work));
schedule.Appointments.Add(CreateAppointment("Travel back home", today.AddHours(17.5), today.AddHours(19), Travel));
schedule.Appointments.Add(CreateAppointment("Family Dinner", today.AddHours(20), today.AddHours(21), Rest));
}
private NAppointment CreateAppointment(string subject, DateTime start, DateTime end, string groupItem)
{
NAppointment appointment = new NAppointment(subject, start, end);
appointment.Groups = new NAppointmentGroupCollection();
appointment.Groups.Add(new NAppointmentGroup("Activity", groupItem));
return appointment;
}
private void SwapGroupings(NViewMode viewMode)
{
NGrouping grouping1 = viewMode.Groupings[0];
NGrouping grouping2 = viewMode.Groupings[1];
viewMode.Groupings.Clear();
viewMode.Groupings.Add(grouping2);
viewMode.Groupings.Add(grouping1);
}
#endregion
#region Event Handlers
private void OnRadioGroupSelectedIndexChanged(NValueChangeEventArgs arg)
{
int selectedIndex = (int)arg.NewValue;
NSchedule schedule = m_ScheduleView.Content;
if (selectedIndex == 0)
{
// Time grouping should be first
if (schedule.DayViewMode.Groupings[0] is NGroupGrouping)
{
SwapGroupings(schedule.DayViewMode);
SwapGroupings(schedule.WeekViewMode);
SwapGroupings(schedule.MonthViewMode);
}
}
else
{
// Schedule group grouping should be first
if (schedule.DayViewMode.Groupings[0] is NDateRangeGrouping)
{
SwapGroupings(schedule.DayViewMode);
SwapGroupings(schedule.WeekViewMode);
SwapGroupings(schedule.MonthViewMode);
}
}
}
#endregion
#region Fields
private NScheduleView m_ScheduleView;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.Schedule
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Public Class Form1
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Text = "NOV WinForms - NGroupingExample"
' Create the NOV example and its controls
Dim exampleContent As NWidget = CreateExampleContent()
Dim exampleControls As NWidget = CreateExampleControls()
If Not exampleControls Is Nothing Then
exampleControls.PreferredWidth = 300
End If
' Place the example and its controls in a pair box
Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
pairBox.FillMode = ENStackFillMode.First
pairBox.FitMode = ENStackFitMode.First
pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)
' Host the example in the form
Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
host.Dock = DockStyle.Fill
Controls.Add(host)
End Sub
#End Region
#Region "Example"
Public Function CreateExampleContent() As NWidget
' Create a simple schedule
Dim scheduleViewWithRibbon As NScheduleViewWithRibbon = New NScheduleViewWithRibbon()
m_ScheduleView = scheduleViewWithRibbon.View
m_ScheduleView.Document.PauseHistoryService()
Try
InitSchedule(m_ScheduleView.Content)
Finally
m_ScheduleView.Document.ResumeHistoryService()
End Try
' Return the commanding widget
Return scheduleViewWithRibbon
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
stack.Add(New NRadioButton("Time grouping first"))
stack.Add(New NRadioButton("Group grouping first"))
Dim groupingOrderGroup As NRadioButtonGroup = New NRadioButtonGroup(stack)
groupingOrderGroup.SelectedIndexChanged += AddressOf OnRadioGroupSelectedIndexChanged
groupingOrderGroup.SelectedIndex = 0
Return groupingOrderGroup
End Function
Public Function GetExampleDescription() As String
Return "
This example demonstrates how to create schedule groups, how to associate a group to appointments and
how to apply grouping to schedule view modes. Each view mode (except for ""Timeline"") has a default
date related grouping, so you can either add a new grouping or insert it before the default one. This
will affect the order in which the groupings are applied. Use the radio button on the right to control
the grouping order.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Schedule Grouping Appointments", "https://www.nevron.com/docs/openvision/schedule-grouping-appointments.html"), ("Schedule Grouping Overview", "https://www.nevron.com/docs/openvision/schedule-grouping-overview.html"), ("Schedule Appointments", "https://www.nevron.com/docs/openvision/schedule-appointments.html"), ("Schedule", "https://www.nevron.com/docs/openvision/schedule.html")}
End Function
#End Region
#Region "Implementation"
Private Sub InitSchedule(schedule As NSchedule)
Const ActivityGroup = "Activity"
Const Work = "Work"
Const Rest = "Rest"
Const Travel = "Travel"
schedule.ViewMode = ENScheduleViewMode.Day
' Add a schedule group
schedule.Groups.Add(New NScheduleGroup(ActivityGroup, New String() {Work, Rest, Travel}))
' Add a grouping to each of the view modes
schedule.DayViewMode.Groupings.Add(New NGroupGrouping(ActivityGroup))
schedule.WeekViewMode.Groupings.Add(New NGroupGrouping(ActivityGroup))
schedule.MonthViewMode.Groupings.Add(New NGroupGrouping(ActivityGroup))
schedule.TimelineViewMode.Groupings.Add(New NGroupGrouping(ActivityGroup))
' Create the appointments
Dim today = Date.Today
schedule.Appointments.Add(CreateAppointment("Travel to Work", today.AddHours(6.5), today.AddHours(7.5), Travel))
schedule.Appointments.Add(CreateAppointment("Meeting with John", today.AddHours(8), today.AddHours(10), Work))
schedule.Appointments.Add(CreateAppointment("Conference", today.AddHours(10.5), today.AddHours(11.5), Work))
schedule.Appointments.Add(CreateAppointment("Lunch", today.AddHours(12), today.AddHours(14), Rest))
schedule.Appointments.Add(CreateAppointment("News Reading", today.AddHours(12.5), today.AddHours(13.5), Rest))
schedule.Appointments.Add(CreateAppointment("Video Presentation", today.AddHours(14.5), today.AddHours(15.5), Work))
schedule.Appointments.Add(CreateAppointment("Web Meeting", today.AddHours(16), today.AddHours(17), Work))
schedule.Appointments.Add(CreateAppointment("Travel back home", today.AddHours(17.5), today.AddHours(19), Travel))
schedule.Appointments.Add(CreateAppointment("Family Dinner", today.AddHours(20), today.AddHours(21), Rest))
End Sub
Private Function CreateAppointment(subject As String, start As Date, [end] As Date, groupItem As String) As NAppointment
Dim appointment As NAppointment = New NAppointment(subject, start, [end])
appointment.Groups = New NAppointmentGroupCollection()
appointment.Groups.Add(New NAppointmentGroup("Activity", groupItem))
Return appointment
End Function
Private Sub SwapGroupings(viewMode As NViewMode)
Dim grouping1 = viewMode.Groupings(0)
Dim grouping2 = viewMode.Groupings(1)
viewMode.Groupings.Clear()
viewMode.Groupings.Add(grouping2)
viewMode.Groupings.Add(grouping1)
End Sub
#End Region
#Region "Event Handlers"
Private Sub OnRadioGroupSelectedIndexChanged(arg As NValueChangeEventArgs)
Dim selectedIndex As Integer = arg.NewValue
Dim schedule = m_ScheduleView.Content
If selectedIndex = 0 Then
' Time grouping should be first
If TypeOf schedule.DayViewMode.Groupings(0) Is NGroupGrouping Then
SwapGroupings(schedule.DayViewMode)
SwapGroupings(schedule.WeekViewMode)
SwapGroupings(schedule.MonthViewMode)
End If
Else
' Schedule group grouping should be first
If TypeOf schedule.DayViewMode.Groupings(0) Is NDateRangeGrouping Then
SwapGroupings(schedule.DayViewMode)
SwapGroupings(schedule.WeekViewMode)
SwapGroupings(schedule.MonthViewMode)
End If
End If
End Sub
#End Region
#Region "Fields"
Private m_ScheduleView As NScheduleView
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class