Version

SelectedDateTimeRange Property

Returns an object which represents the currently selected range of time, or null if there is no date/time selection.
Syntax
'Declaration
 
Public ReadOnly Property SelectedDateTimeRange As DateTimeRange
public DateTimeRange SelectedDateTimeRange {get;}
Remarks

Non-contiguous selection of dates and times is not supported; as such, no property exists through which the developer can change the selection strategy used for date/time selection.

Since non-contiguous selection of dates and times is not supported, a single object can fully represent the current selection. The SelectedDateTimeRange property returns the start and end of the range, which can span across multiple days.

The date/time selection can be programmatically changed by calling the SelectDateTimeRange method, and cleared by calling the ClearSelectedDateTimeRange method.

Note: When the SelectedDateTimeRange is cleared, this property will subsequently return null, until a range is explicitly set. The date/time selection can be cleared programmatically by calling the ClearSelectedDateTimeRange method; it is also cleared when the user selects an Appointment or Holiday, or activates an Owner by clicking on its header.

The SelectedDateTimeRange property is available only at runtime. Its default value is null; no date/time selection is depicted until the user selects a range or the value is programmatically set.

Example
The following code sample demonstrates how to use the date/time selection-related properties, methods, and events:

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

Imports System.Collections.Generic
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinSchedule
Imports System.Diagnostics

    Public Sub SelectDateTimeRange(ByVal control As UltraTimelineView, ByVal range As DateTimeRange)

        '  Handle the SelectedDateTimeRangeChanging event
        RemoveHandler control.SelectedDateTimeRangeChanging, AddressOf Me.OnSelectedDateTimeRangeChanging
        AddHandler control.SelectedDateTimeRangeChanging, AddressOf Me.OnSelectedDateTimeRangeChanging

        '  If the caller did not specify a range, use the default,
        '  i.e., the working hour range of the current day.
        If range Is Nothing Then
            Dim calendarInfo As UltraCalendarInfo = control.CalendarInfo
            Dim dow As Infragistics.Win.UltraWinSchedule.DayOfWeek = calendarInfo.DaysOfWeek(DateTime.Today.DayOfWeek)
            Dim start As DateTime = DateTime.Today.Add(dow.WorkDayStartTime.TimeOfDay)
            Dim _end As DateTime = DateTime.Today.Add(dow.WorkDayEndTime.TimeOfDay).AddSeconds(-1)
            range = New DateTimeRange(start, _end)
        End If

        '  Select the range programmatically
        control.SelectDateTimeRange(range.StartDateTime, range.EndDateTime)
    End Sub

    Private Sub OnSelectedDateTimeRangeChanging(ByVal sender As Object, ByVal e As SelectedDateTimeRangeChangingEventArgs)

        '  If no listeners have canceled the SelectedDateTimeRangeChanging
        '  event, hook the SelectedDateTimeRangeChanged event so we get a
        '  notification after it has changed.
        If e.Cancel = False Then
            Dim control As UltraTimelineView = sender
            AddHandler control.SelectedDateTimeRangeChanged, AddressOf Me.OnSelectedDateTimeRangeChanged
        End If
    End Sub

    Private Sub OnSelectedDateTimeRangeChanged(ByVal sender As Object, ByVal e As SelectedDateTimeRangeChangedEventArgs)

        '  Format the selected date/time range and set the text
        '  of the label control that is used to display it.
        '  Adjust the end time if the PrimaryInterval is a TimeInterval,
        '  so that instead of '9AM - 9:59AM', the user sees '9AM - 10AM'.
        Dim control As UltraTimelineView = sender
        Dim adjustEndTime As Boolean = (control.PrimaryInterval.GetType() Is GetType(TimeInterval))
        Me.lblSelectedRange.Text = DateTimeRange.Format(e.Range.StartDateTime, e.Range.EndDateTime, DateTimeRange.Separator, adjustEndTime)

        '  Detach the event handler
        RemoveHandler control.SelectedDateTimeRangeChanged, AddressOf Me.OnSelectedDateTimeRangeChanged
    End Sub
using System.Collections.Generic;
using Infragistics.Win;
using Infragistics.Win.UltraWinSchedule;
using System.Diagnostics;

    public void SelectDateTimeRange( UltraTimelineView control, DateTimeRange range )
    {
        //  Handle the SelectedDateTimeRangeChanging event
        control.SelectedDateTimeRangeChanging -= new SelectedDateTimeRangeChangingHandler(this.OnSelectedDateTimeRangeChanging);
        control.SelectedDateTimeRangeChanging += new SelectedDateTimeRangeChangingHandler(this.OnSelectedDateTimeRangeChanging);

        //  If the caller did not specify a range, use the default,
        //  i.e., the working hour range of the current day.
        if ( range == null )
        {
            UltraCalendarInfo calendarInfo = control.CalendarInfo;
            Infragistics.Win.UltraWinSchedule.DayOfWeek dow = calendarInfo.DaysOfWeek[DateTime.Today.DayOfWeek];
            DateTime start = DateTime.Today.Add( dow.WorkDayStartTime.TimeOfDay );
            DateTime end = DateTime.Today.Add( dow.WorkDayEndTime.TimeOfDay ).AddSeconds( -1 );
            range = new DateTimeRange( start, end );
        }

        //  Select the range programmatically
        control.SelectDateTimeRange( range.StartDateTime, range.EndDateTime );
    }

    private void OnSelectedDateTimeRangeChanging(object sender, SelectedDateTimeRangeChangingEventArgs e)
    {
        //  If no listeners have canceled the SelectedDateTimeRangeChanging
        //  event, hook the SelectedDateTimeRangeChanged event so we get a
        //  notification after it has changed.
        if ( e.Cancel == false )
        {
            UltraTimelineView control = sender as UltraTimelineView;
            control.SelectedDateTimeRangeChanged += new SelectedDateTimeRangeChangedHandler(this.OnSelectedDateTimeRangeChanged);
        }
    }

    private void OnSelectedDateTimeRangeChanged(object sender, SelectedDateTimeRangeChangedEventArgs e)
    {
        //  Format the selected date/time range and set the text
        //  of the label control that is used to display it.
        //  Adjust the end time if the PrimaryInterval is a TimeInterval,
        //  so that instead of '9AM - 9:59AM', the user sees '9AM - 10AM'.
        UltraTimelineView control = sender as UltraTimelineView;
        bool adjustEndTime = control.PrimaryInterval is TimeInterval;
        this.lblSelectedRange.Text = DateTimeRange.Format( e.Range.StartDateTime, e.Range.EndDateTime, DateTimeRange.Separator, adjustEndTime );

        //  Detach the event handler
        control.SelectedDateTimeRangeChanged -= new SelectedDateTimeRangeChangedHandler(this.OnSelectedDateTimeRangeChanged);
    }
Requirements

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

See Also