DateTimePicker ReadOnly Property

6 posts, 0 answers
  1. Shulla Krous
    Shulla Krous avatar
    13 posts
    Member since:
    Oct 2009

    Posted 02 Oct 2011 Link to this post

    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.

  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 05 Oct 2011 Link to this post

    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 >>

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Shulla Krous
    Shulla Krous avatar
    13 posts
    Member since:
    Oct 2009

    Posted 09 Oct 2011 Link to this post

    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.

  5. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 11 Oct 2011 Link to this post

    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.

  6. Shulla Krous
    Shulla Krous avatar
    13 posts
    Member since:
    Oct 2009

    Posted 23 Oct 2011 Link to this post

    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,

  7. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 24 Oct 2011 Link to this post

    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.

Back to Top
UI for WinForms is Visual Studio 2017 Ready