StrataFrame Forum

DateBox clear value key

http://forum.strataframe.net/Topic26344.aspx

By Victor Sousa - 3/8/2010

I noticed the the F6 key clears the DateBox control and I don't see a property to set that value. What is the best way to set the "delete" key to clear the value?
By Trent L. Taylor - 3/8/2010

Well, this property should be slightly exposed, but delete would technically interfere with other logic in the control. The delete currently deletes any selected text in the control. Let me tinker with this a little to see if it is safe for us to expose this property. The other option is to subclass the DateBox and override the ProcessCmdKey which gives you the base entry point...but this is one of those "Do at your own risk" things. Smile
By Victor Sousa - 3/8/2010



The Delete key doesn't seem to do anything in the DateBox control. It doesn't even clear the highlighted text.
By Charles R Hankey - 3/8/2010

I get that the datebox control is written from the ground up etc and is not just a subclass of the .net datepicker. But I still don't get why. Is it a theme thing?



You know I am a drinker of the Microfour Koolaid but I'm finding the SF wrapped datepicker control does everyting the datebox does and maybe a little more. Realized after adding plus and minus quicken-like keypresses that arrow keys in month day or year worked too.



FWIW this is what I did to mod it in my own UI library :



Imports System.Windows.Forms



Public Class Datepicker

Inherits MicroFour.StrataFrame.UI.Windows.Forms.DateTimePicker



Private Sub dbkeypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

If e.KeyChar() = "+" Or e.KeyChar() = "=" Then

Me.Value = Me.Value.AddDays(1)

End If

If e.KeyChar() = "_" Or e.KeyChar() = "-" Then

Me.Value = Me.Value.AddDays(-1)

End If

If e.KeyChar() = "t" Or e.KeyChar() = "T" Then

Me.Value = System.DateTime.Now()

End If

If e.KeyChar() = "M" Or e.KeyChar() = "m" Then

Dim dt As DateTime = New DateTime(Me.Value.Year, Me.Value.Month, 1)

Me.Value = dt

End If

If e.KeyChar() = "H" Or e.KeyChar() = "h" Then

Dim dt As DateTime = New DateTime(Me.Value.Year, Me.Value.Month + 1, 1)

Me.Value = dt.AddDays(-1)

End If

If e.KeyChar() = "Y" Or e.KeyChar() = "y" Then

Dim dt As DateTime = New DateTime(Me.Value.Year, 1, 1)

Me.Value = dt

End If

If e.KeyChar() = "R" Or e.KeyChar() = "r" Then

Dim dt As DateTime = New DateTime(Me.Value.Year + 1, 1, 1)

Me.Value = dt.AddDays(-1)

End If

If e.KeyChar() = "C" Or e.KeyChar() = "c" Then

SendKeys.Send("%{DOWN}")



End If



End Sub

End Class





BTW, is there a sample of the new calendar thingy around anywhere? Maybe that is what I'm not getting about datebox.



Hehe
By Trent L. Taylor - 3/8/2010

Wow...that is the first time I have heard that.  The number one thing is ease of date entry.  When we tried to use the standard .NET wrapped DateTimepicker in our medical application, we had hate mail coming our way...a lot of it!  In fact, we had several other internal applications that used that control...and we got hate mail from them too.  In fact, I sent my self some hate mail when I had to use it in the real-world. w00t

Once we released the DateBox control in our medical application our users sent us some love notes Tongue  The ease of date entry was the main purpose behind it.  Not to mention total control.  We can enhance this control and do whatever we want with it.  It truth, the standard DateTimepicker is okay if you are just going to have some simple dates popped up there that are not a major piece of your app.  But when it comes to heads down entry and large date entry, it makes a huge difference.

Not that it matters at this point, but we also got some not quite hate mail but definitely not love notes from a number of SF users as well that were passing along complaints from their users. 

I will create a demo at some point, but there is a lot of intelligence in the DateBox that isn't in the DateTimePicker.  For example, in the DateBox, I can enter the control and type "5560" and it will input "05/05/1960" into the control.  It has the inteligence to figure this type of thing out.  You could also type "010180" and it would put "01/01/1980."  Let me put it like this, I was grilled by QA until we made the QA team smile...and it ain't easy to do that! BigGrin

As for the clear command, I will most likely expose this property in the next update and you can do as you like.  This makes sense anyway. Wink

By Victor Sousa - 3/8/2010

Trent, i agree. The DateBox is much better for data entry. i'm just starting w/.Net and Strataframe and started using the datepicker before discovering the DateBox. Datepicker was very quirky and aside from the calender drop down, seemed a step backward coming from VFP date entry. Just need a configurable clear key to make it perfect Smile




By Teddy Jensen - 3/8/2010

Trent,

Will the week start date make in the next build ? Whistling

I would like to use the DateBox, but as earlier mentioned the week in Denmark starts on monday.

By Trent L. Taylor - 3/9/2010

Just need a configurable clear key to make it perfect




I will try and get this in the next update. Wink



Will the week start date make in the next build ?




I will look at this as well and see if we can squeeze this into the next update. Smile
By Ross L. Rooker, Sr. - 2/16/2012

Using the DELETE key would be good in the next build for me also. In the meantime I will add this to the tool tip to at least let the user know.
By Ivan George Borges - 2/16/2012

Hi Ross.

If you feel like it, you can use the workaround I have used.
Subclass the DateBox and add the following code to it:

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        Select Case keyData
            Case Keys.Delete
                '-- Delete key pressed, send an F6 to clear contents
                Return MyBase.ProcessCmdKey(msg, Keys.F6)
        End Select

        Try
            Return MyBase.ProcessCmdKey(msg, keyData)
        Catch ex As Exception
            '-- the DateBox will throw an exception if user use keys to add or subtract beyond the bounderies
            '   so in these cases we will just send Home key
            Return MyBase.ProcessCmdKey(msg, Keys.Home)
        End Try
    End Function

Hope it helps.