views:

843

answers:

4

I have a DateTimePicker (nullable version) that I need to be read only. I'm not happy with the display if it is disabled, so wanted to know if anyone had a nifty example of how to stop updates on the field?

Thanks.

A: 

handle the DateTimePicker.MouseClick Event and set the event.handled to true

PoweRoy
You'd also need to disable keyboard input that would change the value
Rowland Shaw
+1  A: 

You could hook the Changed event, and set the value back to your desired value (if different) -- this way you'll cover any cause for change (via mouse, or keyboard)

Have you considered using a different control, such as a read only textbox or even a label control?

Rowland Shaw
A: 

"I'm not happy with the display if it is disabled"

Why? If it's because a disabled text box looks weird, you can just change the disabled style to make it look normal, or indicate in a prettier way that it accepts input only through the date picker. Possibly have no borders on it, to say it's not really a text box.

Sudhir Jonathan
A: 

How about just picking up the Changed event and setting e.Cancel = true?