Pranjal Kothari
Pranjal Kothari

Reputation: 88

How to disable manual input in a Telerik RadDatePicker

I am using a Telerik RadDatePicker, and I want to disable input by the user, but they should be able to select from the calender.

<telerik:RadDatePicker Culture="{Binding GetLanguage}" x:Name="startDate" 
                       Margin="0,5,0,5" HorizontalAlignment="Left"
                       VerticalAlignment="Center" Grid.Column="1" TabIndex="2"
                       MinWidth="120" Width="120" Height="Auto" MaxHeight="25"
                       KeyDown="filterDate_KeyDown" >
</telerik:RadDatePicker>

I have used KeyDown but it did not help.

Upvotes: 1

Views: 4931

Answers (5)

Maria Mathew
Maria Mathew

Reputation: 11

There is an easy solution to this problem.

Adding the property EnableTyping="false" prevents the user from typing.

<telerik:RadDatePicker runat="server" ID="rdpPreviousDay" EnableTyping="false"></telerik:RadDatePicker>

Upvotes: 1

Michael Gilreath
Michael Gilreath

Reputation: 11

There is a property DateInput-ReadOnly. Set it to true and you should be good to go.

Upvotes: -1

Set the IsHitTestVisible=False, problem solved.

    <telerik:RadDatePicker                          
    SelectedDate="{Binding ValidFrom,Mode=TwoWay}" >
                <telerik:RadDatePicker.Resources>
                    <Style TargetType="telerik:RadWatermarkTextBox">
                        <Setter Property="IsHitTestVisible" Value="False" />                          
                    </Style>
                </telerik:RadDatePicker.Resources>

Upvotes: 0

Sourabh
Sourabh

Reputation: 66

The PreviewKeyDown event exists exactly for this sort of thing.

private void spacebarHandler_PreviewKeyDown(object sender, KeyEventArgs e)
 {
if (e.Key == Key.Space)
    e.Handled = true;
}

Upvotes: 2

Grant Winney
Grant Winney

Reputation: 66501

Subscribe to the KeyDown event:

<telerik:RadDatePicker KeyDown="StartDate_OnKeyDown" />

And then "handle" all keys, which effectively disables the user from typing anything:

private void StartDate_OnKeyDown(object sender, KeyEventArgs e)
{
    e.Handled = true;
}

Interestingly, there's an IsReadOnly property on the RadDatePicker, which disables the DatePickerTextBox and still allows the user to view the calendar, but unfortunately it also prevents the user from actually making a selection in the calendar. It makes it look like you can select a date, but then it doesn't actually set the SelectedDate property.

Upvotes: 0

Related Questions