Re: DTpicker format
From: Rick Rothstein (rickNOSPAMnews_at_NOSPAMcomcast.net)
Date: 08/14/04
- Next message: Ivan Debono: "Re: Licensing controls"
- Previous message: MikeD: "Re: VB datagrid? Force Boolean field as checkbox."
- In reply to: Bob: "Re: DTpicker format"
- Next in thread: Bob: "Re: DTpicker format"
- Reply: Bob: "Re: DTpicker format"
- Reply: Bob: "Re: DTpicker format"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 13 Aug 2004 23:51:57 -0400
> > > I am using a dtpicker in VB 6.0. I was wondering if there is any
way
> > of
> > > knowing:
> > >
> > > 1- how many filed does the control has? For example, in the case
of
> > short
> > > format date it has 3.
> > > 2- which field does currently have the focus?
> > >
> > > I need this information so that I can process the keydown event
for
> > arrow
> > > keys. I am using the dtpicker with a grid. So if the user is on
the
> > first
> > > field and presses the left arrow to hide the dtpicker and transfer
the
> > value
> > > to the grid. I want to achieve a similar thing with the last
field.
> >
> > Are you saying you want to interfere with the way the DatePicker
> > naturally works? Your next to last sentence is not quite clear, but
it
> > seems to indicate that you think pressing the left arrow when the
first
> > field is highlighted somehow exits the control. That is not how my
copy
> > works. The field that is highlighted rotates around wrapping at the
end
> > fields. Personally, I don't think you should interfere with this
method
> > of action (if I were using the program I think you are proposing, I
> > would be quite frustrated every time I used the functionality I know
to
> > be built into this control only to find I had committed some other
> > action). Have you considered just reacting to a press of the Enter
key?
> > That key has no built-in functionality to the DatePicker control and
is
> > sort of a natural action for a user to perform when indicating they
are
> > finished with an action.
> >
> You are correct. Depending the state of some user action, I may need
to
> change the natural behavior of the control. When the user hits the
left
> arrow key, and the state (that I am checking) the date to be
transferred to
> the grid, and the DTpicker to become invisible. This is very similar
to
> what excel does, in a way (except with a text box).
I don't know of any "official" way to track the things you want; but, if
you are up for a kludge, you **might** be able to do what you want.
First off, to find out which format the control is displaying in, simply
ask it.
WhichFormat = DTPicker1.Format
It will return number between 0 and 3 as listed in the Format property
in the Property window for the DatePicker. If you are using 3-dtpCustom
(for a custom format), then you will either know what that format is if
there is but a single custom format or you will have to track which
format is being used in a global variable, or a property defined for
that purpose on the Form if more than one custom format is in use. As
for the order of displaying the month, day and year... either your
program is being used in a single country with a defined Regional Date
Setting or, if used in multiple countries, you will have to query the
system via an API call (or use straight VB to do this somewhat slower)
as to the order of displaying them. Now, here is where the kludge comes
in. Unfortunately, you won't be able to use it with a setting of
dtpLongDate because there is no way to distinguish between the spelled
out day name and the numerical day number (they both change when either
is changed). So, if you are willing to restrict your users to
dtpShortDate, then to decide which field is currently highlighted, use
the following code
Dim CurrentDate As Date
Dim NewDate As Date
Dim NumOfDays As Long
With DTPicker1
.SetFocus
CurrentDate = .Value
SendKeys "{UP}"
DoEvents
NewDate = .Value
SendKeys "{DOWN}"
NumOfDays = DateDiff("d", CurrentDate, NewDate)
End With
If NumOfDays is 1, then the day field is highlighted. If NumOfDays is
greater than 364, the year field is highlighted. Otherwise, the month
field is highlighted. Using the date format you queried the system for
should tell you the position for these fields so you can use that
information to know if it is a left or right field. If you are
displaying times, you can use a similar approach (using "s" as the
argument for DateDiff, adjusting the values to check to 1 for seconds,
60 for minutes, 3600 for hours and 43200 for AM/PM) as shown in the code
above, except you will know the hour field is on the left and the AM/PM
field is on the right.
Rick - MVP
- Next message: Ivan Debono: "Re: Licensing controls"
- Previous message: MikeD: "Re: VB datagrid? Force Boolean field as checkbox."
- In reply to: Bob: "Re: DTpicker format"
- Next in thread: Bob: "Re: DTpicker format"
- Reply: Bob: "Re: DTpicker format"
- Reply: Bob: "Re: DTpicker format"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|