Print Page | Close Window

Datetime Picker - empty date ?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Suite Pro
Forum Description: Topics Related to Codejock Suite Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=18820
Printed Date: 30 January 2025 at 11:45pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Datetime Picker - empty date ?
Posted By: stuc
Subject: Datetime Picker - empty date ?
Date Posted: 12 August 2011 at 9:16am


I'd like to use the datetimepicker as a data entry field but the users must be able to leave the date empty?

Can this be done ?





Replies:
Posted By: Xander75
Date Posted: 13 August 2011 at 2:19am
Yes it can, use the Custom setting that way you can then set the date field as blank. I am not in the office so can't post a code snippet, however if nobody else does I will post it on Monday morning.

-------------
Product: Xtreme SuitePro (ActiveX) v15.3.1
Platform: Windows 7 64-bit (SP1) Professional Edition
Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)


Posted By: Xander75
Date Posted: 13 August 2011 at 2:27am
Hi,

I found a piece of code I had posted a while back in the Controls forum on this.

Private Sub Form_Load()
    With dtpDateOfRequest
        .Value = Format$(Date, "dd/mm/yyyy")
        .Format = xtpPickerCustom
        .CustomFormat = " "
    End With
End Sub

Private Sub dtpDateOfRequest_CloseUp()
    dtpDateOfRequest.Format = xtpPickerShortDate
End Sub


-------------
Product: Xtreme SuitePro (ActiveX) v15.3.1
Platform: Windows 7 64-bit (SP1) Professional Edition
Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)


Posted By: stuc
Date Posted: 15 August 2011 at 4:07am

Thanks fo rthe reply.  This works ok for when the field is first on the screen but I cant trap the delete key for when the user wants to delete the date.

I dont really want to have to put a "delete" button on screen to clear the field.




Posted By: Xander75
Date Posted: 15 August 2011 at 4:21am
Hi stuc,

Yeah I know about the lack of the keydown, keypress & keyup on the DateTimePicker. I rarely use it due to the way it skins (you can't see the day text clearly in some instances). However as a workaround why don't you try this:

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Private Const VK_DELETE = &H2E

Private Sub Form_Load()
    With DateTimePicker
        .Value = Format$(Date, "dd/mm/yyyy")
        .Format = xtpPickerCustom
        .CustomFormat = " "
    End With
End Sub

Private Sub DateTimePicker_CloseUp()
    DateTimePicker.Format = xtpPickerShortDate
End Sub

Private Sub Timer_Timer()
    If CBool(GetAsyncKeyState(VK_DELETE)) Then
        With DateTimePicker
            .Value = Format$(Date, "dd/mm/yyyy")
            .Format = xtpPickerCustom
            .CustomFormat = " "
        End With
    End If
End Sub


Set the timer to be 100 milliseconds, it's crude but works well.


-------------
Product: Xtreme SuitePro (ActiveX) v15.3.1
Platform: Windows 7 64-bit (SP1) Professional Edition
Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)


Posted By: stuc
Date Posted: 15 August 2011 at 4:32am

Thanks, that works but im using it in a form that has several instances of it plus a host of other controls.

I'll fallback to my usual date picker I think.




Posted By: Xander75
Date Posted: 15 August 2011 at 5:21am
Yeah I can understand why you will be best falling back to your usual date picker.

Personally I use the DTPicker from the "Microsoft Windows Common Controls-2 6.0 (SP6)" for the reasons I said above, which can be seen in my other post:  http://forum.codejock.com/forum_posts.asp?TID=17827 - http://forum.codejock.com/forum_posts.asp?TID=17827

-------------
Product: Xtreme SuitePro (ActiveX) v15.3.1
Platform: Windows 7 64-bit (SP1) Professional Edition
Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net