# Programmatic Selection

The date range can be selected through the UI or via the available API of the DateRangePicker component.

The selection can be assigned manually via the `StartDate` and `EndDate` properties of `RadDateRangePicker`.

**Setting the selection range in XAML**

```XAML
<telerik:RadDateRangePicker SelectableDateStart="2024/3/7" SelectableDateEnd="2024/3/27" />
```

**Setting the selection range in C#**

```XAML
this.dateRangePicker.SelectableDateStart = new DateTime(2024, 3, 7);
this.dateRangePicker.SelectableDateEnd = new DateTime(2024, 3, 27);
```

![Picture showing WPF RadDateRangePicker with assigned selection range](https://www.telerik.com/products/wpf/documentation/assets/b13e144276b53f6962262f77442320a2/raddaterangepicker-programmatic-selection-0.png)

## Defining Available Selection Range

The dates available for selection can be limited via the `SelectableDateStart` and `SelectableDateEnd` properties of `RadDateRangePicker`. Setting this will disable all other dates in the calendars.

**Setting the selection range in XAML**

```XAML
<telerik:RadDateRangePicker SelectableDateStart="2024/3/7" SelectableDateEnd="2024/3/27" />
```

**Setting the selection range in C#**

```XAML
this.dateRangePicker.SelectableDateStart = new DateTime(2024, 3, 7);
this.dateRangePicker.SelectableDateEnd = new DateTime(2024, 3, 27);
```

![Picture showing WPF RadDateRangePicker with a limited range of selectable dates](https://www.telerik.com/products/wpf/documentation/assets/c3faac6dfd247e64af953ac3f79006ec/raddaterangepicker-programmatic-selection-1.png)

> To disable a specific set of dates, you can use the [blackout dates](https://www.telerik.com/products/wpf/documentation/controls/raddaterangepicker/blackout-dates) feature.

## Text Selection Action on Focusing the Input Element

By default when you click into the text input element that shows the selected dates, all text gets selected. The DateRangePicker control allows you to alter this behavior via a set of actions that can be applied using the `SelectionOnFocus` enum property. The property allows the following values:

* `Unchanged`—When the text input is focused the selection won't be modified.
* `SelectAll`—When the text input is focused, all text gets selected.
* `CaretToBeginning`—When the text input is focused, the cursor is placed in the beginning of the text.
* `CaretToEnd`—When the text input is focused, the cursor is placed in the end of the text.
* `Default`—When the text input is focused the caret will be placed at the beginning if the text is still not set. Otherwise the position of the cursor won't be changed.
* `DefaultSelectAll`—This behavior behaves like `SelectAll` if the control is focused with a mouse click action. If the text input is focused with the `Tab` key, the behavior is like with the `Default` mode.

## See Also

* [Getting Started](https://www.telerik.com/products/wpf/documentation/controls/raddaterangepicker/getting-started)
* [Events](https://www.telerik.com/products/wpf/documentation/controls/raddaterangepicker/events)
