Thursday, April 14, 2011

How do you set a DateTimePicker to be read only?

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.

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

    Rowland Shaw : You'd also need to disable keyboard input that would change the value
  • 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?

  • "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.

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

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.