Disabled Style on controls.

2 posts, 0 answers
  1. Phillip Foster
    Phillip Foster avatar
    58 posts
    Member since:
    Apr 2010

    Posted 09 May 2011 Link to this post

    I was curious if there was an easy way to change the "disabled" style of controls like "DateTimePicker", "DropDownListBox",etc.

    Basically I want them to be ReadOnly without having to have that Grey backcolor, but obviously just changing the backcolor doesn't work.

    Is there a simple way to do this?
  2. Stefan
    Stefan avatar
    2908 posts

    Posted 12 May 2011 Link to this post

    Hi Phillip,

    Thank you for writing.

    You can make RadDateTimePicker read-only without making the control disabled, by setting the ReadOnly property of the TextBoxItem:
    radDateTimePicker1.DateTimePickerElement.TextBoxElement.TextBoxItem.ReadOnly = true;

    Additionally, you can subscribe to the Opening event of the control, where you can check whether you made the TextBoxItem ReadOnly, and if it is, cancel the drop down:
    void radDateTimePicker1_Opening(object sender, CancelEventArgs e)
        if (radDateTimePicker1.DateTimePickerElement.TextBoxElement.TextBoxItem.ReadOnly)
            e.Cancel = true;

    In regards to RadDropDownList, the same approach can be used:
    radDropDownList1.DropDownListElement.TextBox.TextBoxItem.ReadOnly = true;

    and the PopupOpening event:
    void radDropDownList1_PopupOpening(object sender, CancelEventArgs e)
        if (radDropDownList1.DropDownListElement.TextBox.TextBoxItem.ReadOnly)
            e.Cancel = true;

    Alternatively, instead of making the TextBoxItem ReadOnly, you can set the DropDownStyle of the control to DropDownList, which does not allow editing the editor.

    I hope you find this information useful. Should you have any other questions, do not hesitate to contact us.
    All the best,
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Back to Top