Scrolls the passed-in date into view. If already visible, the method does nothing and returns. If not already visible, the
Week containing the passed-in date is made to be the first or last visible
Week.
This example optimizes the control's display so that only the day with the most appointments is visible.
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinSchedule
Imports Infragistics.Win.UltraWinSchedule.MonthViewSingle
Private Sub OptimizeControlForAppointmentDisplay()
Dim yesterday As DateTime = DateTime.Today.AddDays(-1)
Dim today As DateTime = DateTime.Today
Dim tomorrow As DateTime = DateTime.Today.AddDays(1)
Dim i As Integer
' If there are no activities, let's add a few
' Add appointments
If Me.ultraMonthViewSingle1.CalendarInfo.Appointments.Count = 0 Then
For i = 1 To 5
Me.ultraMonthViewSingle1.CalendarInfo.Appointments.Add(yesterday, "Yesterday's appointment " + i.ToString())
Next
For i = 1 To 3
Me.ultraMonthViewSingle1.CalendarInfo.Appointments.Add(today, "Today's appointment " + i.ToString())
Next
For i = 1 To 10
Me.ultraMonthViewSingle1.CalendarInfo.Appointments.Add(tomorrow, "Tomorrow's appointment " + i.ToString())
Next
End If
' Add notes
If Me.ultraMonthViewSingle1.CalendarInfo.Notes.Count = 0 Then
Me.ultraMonthViewSingle1.CalendarInfo.Notes.Add(yesterday, "Yesterday's note " + i.ToString())
For i = 1 To 2
Me.ultraMonthViewSingle1.CalendarInfo.Notes.Add(today, "Today's note " + i.ToString())
Next
For i = 1 To 5
Me.ultraMonthViewSingle1.CalendarInfo.Notes.Add(tomorrow, "Tomorrow's note " + i.ToString())
Next
End If
' Add a holiday
If Me.ultraMonthViewSingle1.CalendarInfo.Holidays.Count = 0 Then
Me.ultraMonthViewSingle1.CalendarInfo.Holidays.Add(yesterday, "My 2-day Holiday")
End If
' First let's determine which day has the most activity. We do this by counting the occurrences of a given date
' in all the appointments' StartDateTime property, keeping track of the one with the most occurrences
Dim dateWithMostActivity As DateTime = DateTime.Today
Dim count As Integer = 0
Dim tempCount As Integer = 0
Dim outer As Appointment
Dim inner As Appointment
For Each outer In Me.ultraMonthViewSingle1.CalendarInfo.Appointments
tempCount = 0
For Each inner In Me.ultraMonthViewSingle1.CalendarInfo.Appointments
If inner.StartDateTime.Date = outer.StartDateTime Then tempCount += 1
Next
' If this date has more appointments that all others before
' it, adjust the count and set the new dateWithMostActivity
If tempCount > count Then
count = tempCount
dateWithMostActivity = outer.StartDateTime
End If
Next
' If there are no appointments, return without doing anything
If count = 0 Then Return
' Set the CalendarInfo object's FirstDayOfWeek property to the same day of the week
' as the day that has the most appointments
Me.ultraMonthViewSingle1.CalendarInfo.FirstDayOfWeek = dateWithMostActivity.DayOfWeek
' Set the Visible property of all DayOfWeek objects to false,
' except for the one that we want to see
Dim dow As Infragistics.Win.UltraWinSchedule.DayOfWeek
For Each dow In Me.ultraMonthViewSingle1.CalendarInfo.DaysOfWeek
If dow.DayOfTheWeek <> dateWithMostActivity.DayOfWeek Then dow.Visible = False Else dow.Visible = True
Next
' Set the VisibleWeeks property to 1, so we only display the day
' with the most activity
Me.ultraMonthViewSingle1.VisibleWeeks = 1
' Set the CalendarInfo object's ActiveDay property to the same day as the
' date with the most activity
Me.ultraMonthViewSingle1.CalendarInfo.ActiveDay = Me.ultraMonthViewSingle1.CalendarInfo.GetDay(dateWithMostActivity, True)
' Scroll the day into view to ensure that it is visible
Me.ultraMonthViewSingle1.ScrollDayIntoView(dateWithMostActivity, True)
' Since our task here is to optimize the control's display for Appointments,
' let's use the control's ActivityDisplayStyle property to suppress the displaying
' of other activities (Notes and Holidays).
Me.ultraMonthViewSingle1.ActivityDisplayStyle = ActivityDisplayStyleEnum.Appointments
' Dirty and verify all UIElements to update the display
Me.ultraMonthViewSingle1.UIElement.DirtyChildElements()
Me.ultraMonthViewSingle1.UIElement.VerifyChildElements()
' Get the UIElement associated with the day that has the most activity. Then we can use its MoreActivityIndicatorVisible property
' to determine whether there are any remaining appointments that are not being displayed. If there are, we will set the DayOfWeekHeadersVisible property to false, which will give us a little
' more space in which to display the appointments. Note that we can use the ActiveDay as the 'context' parameter to the GetDescendant method, since we set the ActiveDay a few lines above
' to the day with the most appointments
Dim dayUI As Infragistics.Win.UltraWinSchedule.MonthViewSingle.DayUIElement = Me.ultraMonthViewSingle1.UIElement.GetDescendant(GetType(DayUIElement), Me.ultraMonthViewSingle1.CalendarInfo.ActiveDay)
If Not dayUI Is Nothing And dayUI.MoreActivityIndicatorVisible Then
Me.ultraMonthViewSingle1.DayOfWeekHeadersVisible = False
' Since we are hiding the DayOfWeek headers, the name of the
' day of the week will not be displayed anywhere, so set the DayDisplayStyle
' property to Full so that it is displayed in the day header
Me.ultraMonthViewSingle1.DayDisplayStyle = DayDisplayStyleEnum.Full
End If
End Sub
'Declaration
Public Overloads Sub ScrollDayIntoView( _
ByVal As Date, _
ByVal As Boolean _
)
using Infragistics.Win;
using Infragistics.Win.UltraWinSchedule;
using Infragistics.Win.UltraWinSchedule.MonthViewSingle;
using System.Diagnostics;
private void OptimizeControlForAppointmentDisplay()
{
// Declare some date variables to work with
DateTime yesterday = DateTime.Today.AddDays( -1.0F );
DateTime today = DateTime.Today;
DateTime tomorrow = DateTime.Today.AddDays( 1.0F );
// If there are no activities, let's add a few
// Add appointments
if ( this.ultraMonthViewSingle1.CalendarInfo.Appointments.Count == 0 )
{
for ( int i = 1; i <= 5; i ++ )
this.ultraMonthViewSingle1.CalendarInfo.Appointments.Add(yesterday, "Yesterday's appointment " + i.ToString() );
for ( int i = 1; i <= 3; i ++ )
this.ultraMonthViewSingle1.CalendarInfo.Appointments.Add(today, "Today's appointment " + i.ToString() );
for ( int i = 1; i <= 10; i ++ )
this.ultraMonthViewSingle1.CalendarInfo.Appointments.Add(tomorrow, "Tomorrow's appointment " + i.ToString() );
}
// Add notes
if ( this.ultraMonthViewSingle1.CalendarInfo.Notes.Count == 0 )
{
for ( int i = 1; i <= 1; i ++ )
this.ultraMonthViewSingle1.CalendarInfo.Notes.Add(yesterday, "Yesterday's note " + i.ToString() );
for ( int i = 1; i <= 2; i ++ )
this.ultraMonthViewSingle1.CalendarInfo.Notes.Add(today, "Today's note " + i.ToString() );
for ( int i = 1; i <= 5; i ++ )
this.ultraMonthViewSingle1.CalendarInfo.Notes.Add(tomorrow, "Tomorrow's note " + i.ToString() );
}
// Add a holiday
if ( this.ultraMonthViewSingle1.CalendarInfo.Holidays.Count == 0 )
this.ultraMonthViewSingle1.CalendarInfo.Holidays.Add(yesterday, "My 2-day Holiday" );
// First let's determine which day has the most activity
// We do this by counting the occurrences of a given date
// in all the appointments' StartDateTime property, keeping
// track of the one with the most occurrences
//
DateTime dateWithMostActivity = DateTime.Today;
int count = 0, tempCount = 0;
foreach( Appointment outer in this.ultraMonthViewSingle1.CalendarInfo.Appointments )
{
tempCount = 0;
foreach( Appointment inner in this.ultraMonthViewSingle1.CalendarInfo.Appointments )
{
if ( inner.StartDateTime.Date == outer.StartDateTime.Date )
tempCount++;
}
// If this date has more appointments that all others before
// it, adjust the count and set the new dateWithMostActivity
if ( tempCount > count )
{
count = tempCount;
dateWithMostActivity = outer.StartDateTime;
}
}
// If there are no appointments, return without doing anything
if ( count == 0 )
return;
// Set the CalendarInfo object's FirstDayOfWeek property to the same day of the week
// as the day that has the most appointments
this.ultraMonthViewSingle1.CalendarInfo.FirstDayOfWeek = (FirstDayOfWeek)( dateWithMostActivity.DayOfWeek );
// Set the Visible property of all DayOfWeek objects to false,
// except for the one that we want to see
foreach( Infragistics.Win.UltraWinSchedule.DayOfWeek dow in this.ultraMonthViewSingle1.CalendarInfo.DaysOfWeek )
{
if ( (int)(dow.DayOfTheWeek) != (int)(dateWithMostActivity.DayOfWeek) )
dow.Visible = false;
else
dow.Visible = true;
}
// Set the VisibleWeeks property to 1, so we only display the day
// with the most activity
this.ultraMonthViewSingle1.VisibleWeeks = 1;
// Set the CalendarInfo object's ActiveDay property to the same day as the
// date with the most activity
this.ultraMonthViewSingle1.CalendarInfo.ActiveDay = this.ultraMonthViewSingle1.CalendarInfo.GetDay( dateWithMostActivity, true );
// Scroll the day into view to ensure that it is visible
this.ultraMonthViewSingle1.ScrollDayIntoView( dateWithMostActivity, true );
// Since our task here is to optimize the control's display for Appointments,
// let's use the control's ActivityDisplayStyle property to suppress the displaying
// of other activities (Notes and Holidays).
this.ultraMonthViewSingle1.ActivityDisplayStyle = ActivityDisplayStyleEnum.Appointments;
// Dirty and verify all UIElements to update the display
this.ultraMonthViewSingle1.UIElement.DirtyChildElements();
this.ultraMonthViewSingle1.UIElement.VerifyChildElements();
// Get the UIElement associated with the day that has the most
// activity. Then we can use its MoreActivityIndicatorVisible property
// to determine whether there are any remaining appointments that
// are not being displayed. If there are, we will set the
// DayOfWeekHeadersVisible property to false, which will give us a little
// more space in which to display the appointments.
//
// Note that we can use the ActiveDay as the 'context' parameter to the
// GetDescendant method, since we set the ActiveDay a few lines above
// to the day with the most appointments
DayUIElement dayUI = this.ultraMonthViewSingle1.UIElement.GetDescendant( typeof(DayUIElement), this.ultraMonthViewSingle1.CalendarInfo.ActiveDay ) as DayUIElement;
if ( dayUI != null && dayUI.MoreActivityIndicatorVisible )
{
this.ultraMonthViewSingle1.DayOfWeekHeadersVisible = false;
// Since we are hiding the DayOfWeek headers, the name of the
// day of the week will not be displayed anywhere, so set the DayDisplayStyle
// property to Full so that it is displayed in the day header
this.ultraMonthViewSingle1.DayDisplayStyle = DayDisplayStyleEnum.Full;
}
}
'Declaration
Public Overloads Sub ScrollDayIntoView( _
ByVal As Date, _
ByVal As Boolean _
)
Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2