Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Enterprise Development / December 2005



Tip: Looking for answers? Try searching our database.

DTpicker control question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robertico - 03 Dec 2005 16:57 GMT
I have an application with a DTpicker control displaying hours and minutes.
When the control gets the focus (using Tab key), the digits for the hours
are selected.
When a user hits the Tab key again, another control gets the focus.

Is it possible to set the focus to the digits for the minutes, instead of
another control ?

Regards,

Robertico
Rick Rothstein [MVP - Visual Basic] - 03 Dec 2005 18:36 GMT
> I have an application with a DTpicker control displaying hours and minutes.
> When the control gets the focus (using Tab key), the digits for the hours
[quoted text clipped - 3 lines]
> Is it possible to set the focus to the digits for the minutes, instead of
> another control ?

Right and Left arrow keys change fields, Up and Down arrow keys change
values.

Rick
MikeD - 04 Dec 2005 01:47 GMT
>I have an application with a DTpicker control displaying hours and minutes.
> When the control gets the focus (using Tab key), the digits for the hours
[quoted text clipped - 3 lines]
> Is it possible to set the focus to the digits for the minutes, instead of
> another control ?

If you mean you always want the minutes field to be "active" whenever the
control itself gets focus, no, I don't think there is (I even looked in the
Platform SDK to see if there was a message you could send to do
this...nothing). Rick already explained that you use the right and left
arrow keys to move between fields. Using Tab to do this would be extremely
non-standard and probably only confuse and/or frustrate users.  Standard
behavior for the Tab key is to move focus from control to control, not move
from field to field within a control (of course, there are always
exceptions).

Signature

Mike
Microsoft MVP Visual Basic

Graeme - 05 Dec 2005 23:53 GMT
On or about 4/12/2005 3:57 AM,  Robertico was seen in the vicinity and
allegedly stated:

>I have an application with a DTpicker control displaying hours and minutes.
>When the control gets the focus (using Tab key), the digits for the hours
[quoted text clipped - 9 lines]
>
>  

I asume you want the control to /start/ in the hours, then move to the
minutes when the user presses 'tab'???

You could use:

   * LostFocus event - you can insert code to:
         o check if the monutes have been altered
         o set the focus back to the dtp control
         o use the 'SendKeys' method to press the right-arrow for the user
   * Keypress event - this is not just for a form, but can be used for
     any object.  It allows you to capture all the keys pressed while
     that object has focus, then to handle that keypress however you
     like.  Ideally you could discard the keys you don't want, and just
     call a function or sub for the 'tab' key which would do similar
     actions to those above.
   * Use separate controls for hours, minutes, seconds, etc.  Set the
     max/min ranges for separate spinner controls (0-23,0-59,0-59) and
     set the tab order to go from one to the next.  Use code in the
     'lostFocus' event for them to transfer the value to variables,
     then use the DateValue() function (or your own function) to get a
     combined time value.

Lots of ways to get this done - defninitely not impossible.  Read the
MSDN/help documentation for the keypress event carefully before using
it, as an incorrectly written block of code here will either capture or
discard /all/ input from the keyboard and leave you no way to exit that
control (or you application).

Have fun!

>  
Robertico - 07 Dec 2005 03:46 GMT
> I asume you want the control to /start/ in the hours, then move to the
> minutes when the user presses 'tab'???

Thats correct.

My users ask me for that. As Mike mentioned , there are always
exceptions.

Thanks for the replies and solutions.

Robertico
Gman - 07 Dec 2005 05:21 GMT
I can completely understand why users have requested this. The
datetimepicker is often considered *horrible* for entering times since
most users use the numeric keypad and hopping your hand backwards and
forwards between the cursor keys and the keypad is very cumbersome.

I would propose you point out to the users that they can use the "." on
the numeric keypad rather than the right cursor key (and then tap it
again to return to the start of the control if necessary). It's not very
intuitive but it does work - and is very quick and easy.

Furthermore, if all they need to enter is hh:mm then use the custom
format and let them enter just that - don't leave it as the default
hh:mm:ss for time.

If this doesn't appease them then my own preference (rather than using
DTP) is to use a text box whereby they can type in 0930 and I would mask
it to 09:30. I also use this to accept 9 or 09 (say) and convert it to
09:00 as soon as they tab out, saving on keystrokes. Note that this
approach works beautifully in 24hr clock regions, less so in the US
where you have that whole am/pm faffle to deal with.

>>I asume you want the control to /start/ in the hours, then move to the
>>minutes when the user presses 'tab'???
[quoted text clipped - 7 lines]
>
> Robertico
Andy DF - 12 Dec 2005 09:29 GMT
Are you aware of the fact that the DTPicker will move field focus with
CTRL+Tab?

Also, I've noticed that if the DTPicker is the only control on the form, Tab
key presses will actually move field focus.
This is also true when there are sevral controls and they're all set with
TabStop = True. I'm guessing you could write a routine to set all controls
in a form to have the TabStop property set to False when the DTPicker
recieves the focus and somehow reset it to True when the the user is done
with it.

HTH,
Andy.
Rick Rothstein [MVP - Visual Basic] - 12 Dec 2005 13:36 GMT
> Also, I've noticed that if the DTPicker is the only control
> on the form, Tab key presses will actually move field focus.
> This is also true when there are sevral controls and they're
> all set with TabStop = True.

I presume this is a typo and you meant to write TabStop=False.

> I'm guessing you could write a routine to set all controls in
> a form to have the TabStop property set to False when the
> DTPicker recieves the focus

That is easy enough to do...

   Private Sub DTPicker1_GotFocus()
     Dim C As Control
     For Each C In Me.Controls
       C.TabStop = False
     Next
   End Sub

> and somehow reset it to True when the the user is done with it.

This code will do that...

   Dim C As Control
   For Each C In Me.Controls
     C.TabStop = True
   Next

But the real problem is deciding where to execute it from. I guess the user
would have to click his/her way off of the DatePicker control once he/she
has entered it. If so, then I guess putting this code in the LostFocus event
would be alright. See, that is the problem when one tries to change the
native behavior of Windows, one then has to figure out how to get the user
to vary the natural way they interact with it.

Rick
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.