This is a migrated thread and some comments may be shown as answers.

DatePicker select range

1 Answer 110 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Shawn
Top achievements
Rank 1
Shawn asked on 30 Mar 2011, 07:58 PM
I am trying to use the datePicker to select a range of dates. I enabled SelectionMode Extended using the following.
<telerik:RadDatePicker Width="200" DateTimeWatermarkContent="Select date span">
    <telerik:RadDatePicker.CalendarStyle>
        <Style TargetType="telerik:RadCalendar">
            <Setter Property="SelectionMode" Value="Extended" />
        </Style>
    </telerik:RadDatePicker.CalendarStyle>
</telerik:RadDatePicker>

However this would not allow me to drag the mouse to select a date range. Seems like something else captures the MouseButtonDown.

Is there a way to select a range of dates using the DatePicker?

1 Answer, 1 is accepted

Sort by
0
Shawn
Top achievements
Rank 1
answered on 31 Mar 2011, 12:54 AM
Using a RadDropDownButton made for a nice work around.

<telerik:RadDropDownButton x:Name="btnDateSpan" Margin="35,0,0,0" Content="Select date span">
    <telerik:RadDropDownButton.DropDownContent>
        <telerik:RadCalendar x:Name="calDateSpan" SelectionMode="Extended" SelectionChanged="calDateSpan_SelectionChanged" />
    </telerik:RadDropDownButton.DropDownContent>
</telerik:RadDropDownButton>

The date ranges that can be selected can have empty gaps, but this currently isn't an issue for me.
DateTime dateMin, dateMax;
private void calDateSpan_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
{
    if (calDateSpan.SelectedDates.Count == 0)
        return;
 
    DateTime curMin = calDateSpan.SelectedDates.Min(),
        curMax = calDateSpan.SelectedDates.Max();
 
    bool rangeChange = false;
    if (dateMin != curMin)
    {
        dateMin = curMin;
        rangeChange = true;
    }
 
    if (dateMax != curMax)
    {
        dateMax = curMax;
        rangeChange = true;
    }
 
    if (rangeChange)
        btnDateSpan.Content = dateMin.ToString("d") + "-" + dateMax.ToString("d");
}
Tags
DatePicker
Asked by
Shawn
Top achievements
Rank 1
Answers by
Shawn
Top achievements
Rank 1
Share this question
or