DatePicker select range

2 posts, 0 answers
  1. Shawn
    Shawn avatar
    10 posts
    Member since:
    Mar 2011

    Posted 30 Mar 2011 Link to this post

    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?
  2. Shawn
    Shawn avatar
    10 posts
    Member since:
    Mar 2011

    Posted 30 Mar 2011 Link to this post

    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");
    }
  3. DevCraft banner
Back to Top