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

Disabled Style on controls.

1 Answer 34 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Phillip Foster
Top achievements
Rank 1
Phillip Foster asked on 09 May 2011, 09:59 PM
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?

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 12 May 2011, 08:37 AM
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,
Stefan
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.
Tags
General Discussions
Asked by
Phillip Foster
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or