Back to Devexpress

DateEdit.SelectedRanges Property

windowsforms-devexpress-dot-xtraeditors-dot-dateedit-82f1dd83.md

latest3.5 KB
Original Source

DateEdit.SelectedRanges Property

Gets or sets selected date ranges.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[Browsable(false)]
public DateRangeCollection SelectedRanges { get; }
vb
<Browsable(False)>
Public ReadOnly Property SelectedRanges As DateRangeCollection

Property Value

TypeDescription
DevExpress.XtraEditors.Controls.DateRangeCollection

A collection of selected date ranges.

|

Remarks

The SelectedRanges collection contains DevExpress.XtraEditors.Controls.DateRange objects. The DateRange object includes dates that are EQUAL OR GREATER THAN the DateRange.StartDate and LESS THAN the DateRange.EndDate.

This following code snippet does the following:

  • Activates multiple date selection for a calendar control.

  • Selects two date ranges: one in the past (10 to 5 days ago) and one in the future (4 to 10 days from today).

  • C#

  • VB.NET

csharp
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;

// Enable multiple date selection in the calendar control.
calendarControl1.SelectionMode = CalendarSelectionMode.Multiple;

// Add two date ranges to the calendar's selected ranges:
// - First range: from 10 days ago to 5 days ago.
// - Second range: from 4 days in the future to 10 days in the future.
calendarControl1.SelectedRanges.AddRange(new DateRange[] {
    new DateRange(DateTime.Today.AddDays(-10), DateTime.Today.AddDays(-5)),
    new DateRange(DateTime.Today.AddDays(4), DateTime.Today.AddDays(10))
});
vb
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraEditors.Repository

' Enable multiple date selection in the calendar control.
calendarControl1.SelectionMode = CalendarSelectionMode.Multiple

' Add two date ranges to the calendar's selected ranges:
' - First range: from 10 days ago to 5 days ago.
' - Second range: from 4 days in the future to 10 days in the future.
calendarControl1.SelectedRanges.AddRange(New DateRange() {
    New DateRange(DateTime.Today.AddDays(-10), DateTime.Today.AddDays(-5)),
    New DateRange(DateTime.Today.AddDays(4), DateTime.Today.AddDays(10))
})

The image blow illustrates the result:

Use the IsDateSelected method to check whether a specific date is selected:

csharp
bool isSelected = calendarControl1.SelectedRanges.IsDateSelected(DateTime.Today.AddDays(5));
vb
Dim isSelected As Boolean = calendarControl1.SelectedRanges.IsDateSelected(DateTime.Today.AddDays(5))

See Also

SelectionChanged

SelectionMode

DateEdit Class

DateEdit Members

DevExpress.XtraEditors Namespace