CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Feb 2005
    Posts
    131

    Question Blank DateTimePicker

    I m using datetimepicker in my form and i want when user click on new button then it set the datetimepicker value to blank.

    Is this possible to set the values of dtpicker to null or is there any other control available which can be used instead of DateTimePicker?


    Thanks In advance

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Blank DateTimePicker

    Code:
    DTPicker1.CheckBox = True
    	DTPicker1.Value = Null
    remember the date will be displayed in the DTPicker, however when you try to access the Value property, it will return null..

    you cannot have a Blank DTPicker...

  3. #3
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Blank DateTimePicker

    Quote Originally Posted by vb_the_best
    [code]DTPicker1.CheckBox = True

    you cannot have a Blank DTPicker...
    yes, you can..

    set the format to 3: dtpCustomFormat
    then in the custom page, set the format to a space


    it makes it appear blank, but this is NOT a good idea, because it then looks like a combobox

    note: to get it to show anything the user picks, you must change the format when they pick something, otherwise the date value will always be formatted as a space (dumm..)

    Private Sub DTPicker1_Change()
    DTPicker1.Format = dtpCustom
    DTPicker1.CustomFormat = "yyyy MM dd"
    End Sub
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  4. #4
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Blank DateTimePicker

    Seems to me there is a property which adds a checkbox to the left of the date, and the user can check the box if they want to use the date shown. I haven't really looked at that much though.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  5. #5
    Join Date
    Nov 2005
    Posts
    17

    Exclamation Re: Blank DateTimePicker

    Quote Originally Posted by WizBang
    Seems to me there is a property which adds a checkbox to the left of the date, and the user can check the box if they want to use the date shown. I haven't really looked at that much though.
    This will work very well if you can use the change in state of the check box. If the checkbox is selected, the fontcolour is black, if the checkbox is not selected, the fontcolour = the backcolour, BUT HOW TO DO THIS ???

  6. #6
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Blank DateTimePicker

    Quote Originally Posted by jvzmuller
    This will work very well if you can use the change in state of the check box. If the checkbox is selected, the fontcolour is black, if the checkbox is not selected, the fontcolour = the backcolour, BUT HOW TO DO THIS ???
    The problem is that the color is internally set to appear "grayed". I doubt it is easy to override that behavior, if not impossible.

    Suppose you disable the control instead? You can use a seporate checkbox next to it to enable/disable it.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  7. #7
    Join Date
    Nov 2005
    Posts
    17

    Question Re: Blank DateTimePicker

    Quote Originally Posted by WizBang
    The problem is that the color is internally set to appear "grayed". I doubt it is easy to override that behavior, if not impossible.

    Suppose you disable the control instead? You can use a seporate checkbox next to it to enable/disable it.
    Is it possible to fire the checkbox in the DateTimePicker remotely from another checkbox. I mean can you select one checkbox and it will select the checkbox in the DateTimePicker?

  8. #8
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Blank DateTimePicker

    Quote Originally Posted by jvzmuller
    Is it possible to fire the checkbox in the DateTimePicker remotely from another checkbox. I mean can you select one checkbox and it will select the checkbox in the DateTimePicker?
    That's probably possible, but how will it help achieve your objective? The user can already click the checkbox inside the DTPicker. Then there is still the issue of setting the color. Even if that can be done, when the user highlights the hidden date, it will show up anyway.

    If you don't want to disable the control, then perhaps set the Visible property to False, so it will not be seen?
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  9. #9
    Join Date
    Nov 2005
    Posts
    17

    Question Re: Blank DateTimePicker

    Quote Originally Posted by WizBang
    That's probably possible, but how will it help achieve your objective? The user can already click the checkbox inside the DTPicker. Then there is still the issue of setting the color. Even if that can be done, when the user highlights the hidden date, it will show up anyway.

    If you don't want to disable the control, then perhaps set the Visible property to False, so it will not be seen?
    The origin of the problem is because I am to stupid to know how to delete the date field. What I want to do is to have several text boxes on a form. some of the textboxes are linked to date fields in an Access table. I have amongs others EDIT and UPDATE buttons. If you click the EDIT button, all the textboxes are enabled and you can edit or delete text in textboxes. If you hit the UPDATE button, it must update the table. After strugling for a long time I entered code in the UPDATE button to detect which date field has been delete and to set that field to NULL with a SQL command. It continue to give me an error allthough if you close the form and re-open it, the date field has been deleted. After many attempts I try to work with the DateTimePicker, the only problem is that it cannot be blank. It handle the delete of that date field easily. So if I can "remotely trigger" the check box, I can make the Date Time Picker invisible. I will put a textbox and the datetimepicker link to the same field. I want to code the textbox lostfocus event to set the checkbox in the date time picker to unchecked if the textbox is empty. (Does all this make sense???)

  10. #10
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Blank DateTimePicker

    I see. Thanks for explaining it.

    I think I'd try to avoid using the DTPicker, though it might help with keeping date formats as needed.

    If you try to set a textbox to NULL, it will give an error. I don't know if that was part of the problem, but if you have any NULL fields tied to textboxes, you can use a vbNullString to avoid the error.

    Something like this:
    Code:
    Text1 = NULL_From_DB & vbNullString
    It might also be that the date field doesn't accept a vbNullString as a value, which is what an empty textbox is.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  11. #11
    Join Date
    Nov 2005
    Posts
    17

    Question Re: Blank DateTimePicker

    Quote Originally Posted by WizBang
    I see. Thanks for explaining it.

    I think I'd try to avoid using the DTPicker, though it might help with keeping date formats as needed.

    If you try to set a textbox to NULL, it will give an error. I don't know if that was part of the problem, but if you have any NULL fields tied to textboxes, you can use a vbNullString to avoid the error.

    Something like this:
    Code:
    Text1 = NULL_From_DB & vbNullString
    It might also be that the date field doesn't accept a vbNullString as a value, which is what an empty textbox is.
    Thank you for your time. I have tried that it still give me that same error.

  12. #12
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Blank DateTimePicker

    What was the error you got? When did it occur? Was it a database driver error, or was it generated by the code in your program? If the error is from the database driver, and you have the textbox bound to the db, that might be a problem for fields that can return NULL. I don't know what happenes in that case, since I've never tried binding a textbox to a date field.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured