Re: System.Windows.Forms.DateTimePicker
- From: "Earl" <brikshoe@xxxxxxxxxxxxxxxxx>
- Date: Fri, 27 Apr 2007 07:23:59 -0400
As a last resort, you might use one technique that I used with the old VBCE
grids, and that is to "float" the textbox over whatever cell the user
selects, then transfer the contents of the masked textbox to the grid when
the user leaves that cell.
"RobinS" <RobinS@xxxxxxxxxxxxxxx> wrote in message
news:E_OdnRJ25dTN7qzbnZ2dnUVZ_qSrnZ2d@xxxxxxxxxxxxxx
Heh heh heh heh heh.
I'm binding business objects to the masked text box instead of a dataset
or datatable field.
So what I did was added a text representation of my date field to the
class in my business layer. So I have StartDate (a nullable date) and
TextStartDate (a string).
The binding is to the TextStartDate. The binding is done not as a date,
but as ##/##/##. This makes them put in numbers, but not a date
necessarily.
So when they tab out of the field, I do the validation to make sure it's a
date. If the field is null (which will happen if they put in 00/00/00
because that's how my binding is set up) or the field is " / /" (which
is how it looks if they hit <delete> to clear out the date), I store null
in my StartDate.
Otherwise, I validate it as a date using TryParseExact (looking for
MM/dd/yy). If it validates, I move it into StartDate. Otherwise, it's a
marked as an error on the screen (I use iErrorProvider, so they can get
out of the field).
The TextStartDate property sets the StartDate property. It's the only
thing that sets the StartDate property.
When the data is loaded into the business object, it checks the StartDate
for null; if it's null, it sets TextStartDate to string.Empty, otherwise
it formats it as "MM/dd/yy".
There's probably a way to do this with dataset fields, but I'd have to
tinker with it to try it out. Luckily, I don't have that problem.
Does anybody know how to put a masked textbox in a datagridview control?
I'd like to implement this logic there.
Robin S.
---------------------------------
"Earl" <brikshoe@xxxxxxxxxxxxxxxxx> wrote in message
news:%23nCvgBEiHHA.5052@xxxxxxxxxxxxxxxxxxxxxxx
Robin, how are you "letting the user blank out the field"?
"RobinS" <RobinS@xxxxxxxxxxxxxxx> wrote in message
news:nNednanLiJqJU7PbnZ2dnUVZ_u2mnZ2d@xxxxxxxxxxxxxx
Yes, you're right. I finally figured out how to get it to let my user
blank out the date and tab out of the field, and that's about all I
really needed.
Robin S.
-------------------------------
"Earl" <brikshoe@xxxxxxxxxxxxxxxxx> wrote in message
news:eS1gc7jhHHA.4704@xxxxxxxxxxxxxxxxxxxxxxx
Oh heck, even the masked textbox has issues. I just used a plain
textbox and validated the user input manually.
"RobinS" <RobinS@xxxxxxxxxxxxxxx> wrote in message
news:NemdnSz-Y82kPbDbnZ2dnUVZ_ualnZ2d@xxxxxxxxxxxxxx
An addendum to *that* idea -- send all of your users calendars, and
use a masked textbox instead. ;-)
Robin S.
--------------------------
"Earl" <brikshoe@xxxxxxxxxxxxxxxxx> wrote in message
news:%23YkTgmhhHHA.4600@xxxxxxxxxxxxxxxxxxxxxxx
An addendum to that idea. It assigns today's date to all values that
are Empty or Null. This might be resolvable in the Parse/Format
handlers. Maybe someone else has something to add.
"Earl" <brikshoe@xxxxxxxxxxxxxxxxx> wrote in message
news:e8mxzahhHHA.4076@xxxxxxxxxxxxxxxxxxxxxxx
I've actually cobbled together a scheme that might work for dates
(for Time, just flat forget about this cutesy little control if you
are binding, it aint happening, at least not very easily). Here's
what I'm doing for the dates:
1. Add Parse and Format handlers on Form Load or in the constructor
2. Clear the DTPs on Form Load
3. Use the Custom format
4. Use smalldatetime as datatype
5. Do NOT use the checked box
5. Use the Advanced property of the binding to select the simple
Date Time format (4/23/2007)
But here is the clincher:
Before you EndEdit,
1. Set a DateTime variable and assign the DTP value to that
variable:
Dim dateAppt As DateTime
dateAppt = dtpApptDate.Value
2. Call Validate() on the Form (Me.Validate())
Before you submit the update, pass the variable into the row:
ApptBindingSource.EndEdit()
Dim intRowPosition As Integer = ApptBindingSource.Position
DsCustomers.Appointments.Rows(intContactRowPosition)("ApptDate")
= dateAppt
I'm going to give this one last go. But maaaaaaaaaaaaaan, what a
bunch of nonsense! Just to bind a datetime...
"RobinS" <RobinS@xxxxxxxxxxxxxxx> wrote in message
news:tvCdnX6WZopKObbbnZ2dnUVZ_u6rnZ2d@xxxxxxxxxxxxxx
Don't hold back! Tell us how you really feel! ;-)
I agree with Earl.
Robin S.
-------------------------------
"Earl" <brikshoe@xxxxxxxxxxxxxxxxx> wrote in message
news:OR%23sQJPhHHA.4844@xxxxxxxxxxxxxxxxxxxxxxx
You ever see a turtle laying on its back? The DateTimePicker from
Microsoft might possibly be the most defective control ever
foisted upon developers. It's a cutesy little control, but I don't
think it was designed for anything serious. To do any real work
with it, you have to build a workaround for nearly everything (see
my previous posts on this subject). For binding purposes, each
workaround creates additional issues. I have given up on the
godforsaken thing, as it is just a time sink.
<Rabia.Abrar@xxxxxxxxx> wrote in message
news:1177254677.941078.155410@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am using System.Windows.Forms.DateTimePicker in framework 2.0. I
want to provided the user with such a functionality, say, that if
an
item is not received then the datetime instance bound to my
datetimepicker should be null. otherwise it should be whatever
the
user chooses. For this I have to detect the checkedchanged event
of
datetimepicker. Life would have been easier if such an event
existed,
but it does not. The problem with valuechanged event is that it
DOES
NOT fire some of the times when a user changes the checked
property of
the control.
What I want to do is that whenever the user unchecks the control,
i
want to set that date to dbnull. Obviosly, the Value property of
this
control cant have dbnull. So i have no problem even if i have to
get
that particular datarow and manually set the date to dbnull. But
the
problem is the catching of the event of change of Checked
property.
I know I can add a "bit" column in my table for this and bind it
to
the checked property.
Or I can add a separate checkbox near that datetimepicker and
then
implement my desired functionality.
But does anyone have any suggestions to implement this
functionality
without disturbing my database and without disturbing the layout
of my
form?
.
- Follow-Ups:
- Re: System.Windows.Forms.DateTimePicker
- From: RobinS
- Re: System.Windows.Forms.DateTimePicker
- From: RubyDotNet
- Re: System.Windows.Forms.DateTimePicker
- References:
- System.Windows.Forms.DateTimePicker
- From: Rabia . Abrar
- Re: System.Windows.Forms.DateTimePicker
- From: Earl
- Re: System.Windows.Forms.DateTimePicker
- From: RobinS
- Re: System.Windows.Forms.DateTimePicker
- From: Earl
- Re: System.Windows.Forms.DateTimePicker
- From: Earl
- Re: System.Windows.Forms.DateTimePicker
- From: RobinS
- Re: System.Windows.Forms.DateTimePicker
- From: Earl
- Re: System.Windows.Forms.DateTimePicker
- From: RobinS
- Re: System.Windows.Forms.DateTimePicker
- From: Earl
- Re: System.Windows.Forms.DateTimePicker
- From: RobinS
- System.Windows.Forms.DateTimePicker
- Prev by Date: Re: Insert URI into richtext box that has imbedded blanks?
- Next by Date: Re: System.Windows.Forms.DateTimePicker
- Previous by thread: Re: System.Windows.Forms.DateTimePicker
- Next by thread: Re: System.Windows.Forms.DateTimePicker
- Index(es):
Relevant Pages
|