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

DateTimePicker ReadOnly Property

5 Answers 686 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Shulla Krous
Top achievements
Rank 1
Shulla Krous asked on 02 Oct 2011, 12:00 PM

Hi,

I would like to defined the ReadOnly Property to DateTimePicker control.

The Enabled property does not supply our needs.

I have seen different solutions for this problem in the website

but they did not answer the following criteria's:

1 The user will be able to copy the content of the control.

2 The control will not change its visual display look.

                                          

Regards,

Namma.

5 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 05 Oct 2011, 12:37 PM
Hi Naama,

Thank you for writing.

RadDateTimePicker does not support ReadOnly mode out of the box. But you can easily achieve ReadOnly behavior. For this purpose, handle and cancel ValueChanging event.
Please refer to the attached sample project.

I hope this helps.

Greetings,
Peter
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Shulla Krous
Top achievements
Rank 1
answered on 09 Oct 2011, 11:37 AM

Hi,

Thank you for your answer.

We tried your solution, but we found that it does not take into consideration updating the value of DateTimePicker programmatically.

When the Control value is updated programmatically, the update action is canceled too.

This issue caused many critical bugs in our product.

We would like the ReadOnly behavior of the DateTimePicker to be equal to the ReadOnly behavior of the TextBox.   

Regards,

Namma.

0
Peter
Telerik team
answered on 11 Oct 2011, 08:36 AM
Hello Naama,

I would like to suggest using an internal flag that allows for (or not) updating the value. In addition, I would suggest creating a method UpdateDateTimePickerValue that allows for updating the value easily, for example:

bool isReadOnly = true;
void radDateTimePicker1_ValueChanging(object sender, Telerik.WinControls.UI.ValueChangingEventArgs e)
{
            e.Cancel = this.isReadOnly;
}       

private void UpdateDateTimePickerValue(DateTime newValue)
{
            this.isReadOnly = false;
            this.radDateTimePicker1.Value = newValue;
            this.isReadOnly = true;
}

Please refer to the modified project that demonstrates this approach.

I hope this helps.

Kind regards,
Peter
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Shulla Krous
Top achievements
Rank 1
answered on 23 Oct 2011, 12:07 PM

b.s.

Hello Telerik Team,

Thank you for the answer, but the solution that was suggested,

does not fit work regulation and basic standards,

Implementing the solution will cause many updates throw out the project.

And changing of work regulation for all the present and future staff.

                                                                  

One of our programmers has found a genius solution for this problem:

Checking the readOnly state and FocusedElement state of the DateTimePicker control in the ValueChanged event,

And canceling the change accordingly:  

 

if (this.readOnly && this.FocusedElement != null)

  {e.Cancel = true;}

 

 

We would like to receive feedback for this solution.

Upgrading of our points will be very mush appreciated.

Naama,

0
Peter
Telerik team
answered on 24 Oct 2011, 03:00 PM
Hello Naama,

Thank you for sharing your solution for adding the FocusedElement property with us.

I have updated your Telerik points.

Do not hesitate to contact us if you have additional questions.

Regards,
Peter
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Shulla Krous
Top achievements
Rank 1
Answers by
Peter
Telerik team
Shulla Krous
Top achievements
Rank 1
Share this question
or