473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

how to spin the date (a new control in C#)

I have VS 2005 (C#)
There is a control numericUpDown so you can spin numeric values. What I need
to do is to spin date (+- one day). How to do that? Moreover, I want a user
to type the date as well. So the control should validate the typed values on
the fly. Is it possible?
Mar 13 '07 #1
3 2824
Yes.
Create a UserControl and add a datetimepicker and a button above and below.
Hook up the buttons to an event and in the event set the "Value" property of
the datetimepicker to the current Value.AddDay(1) or Value.AddDay(-1)
depending on if the button will make the date go up or down.
If you specify that the format used in the datetimepicker is "Custom" then
you can specify a CustomFormat string, like "MM/dd/yy" for US time. The user
will be able to type into this control although they will have to use the
arrow keys to change which part of the date they are editing. A hidden
benefit is that they can also use the Arrow Up and Down keys to move the
selected part of the date "up" or "down".
The datetimepicker also has inbuilt validation.
"Chris" <Ch***@discussions.microsoft.comwrote in message
news:AD**********************************@microsof t.com...
I have VS 2005 (C#)
There is a control numericUpDown so you can spin numeric values. What I
need
to do is to spin date (+- one day). How to do that? Moreover, I want a
user
to type the date as well. So the control should validate the typed values
on
the fly. Is it possible?

Mar 13 '07 #2
Is there a different way? I did it this way (but unfortunatelly without
letting user type the date). I put textbox (read only) and numericupdown
control. It works ok.
But how to validate (during typing) values typed (by a user) into the textbox?


"Simon Tamman" wrote:
Yes.
Create a UserControl and add a datetimepicker and a button above and below.
Hook up the buttons to an event and in the event set the "Value" property of
the datetimepicker to the current Value.AddDay(1) or Value.AddDay(-1)
depending on if the button will make the date go up or down.
If you specify that the format used in the datetimepicker is "Custom" then
you can specify a CustomFormat string, like "MM/dd/yy" for US time. The user
will be able to type into this control although they will have to use the
arrow keys to change which part of the date they are editing. A hidden
benefit is that they can also use the Arrow Up and Down keys to move the
selected part of the date "up" or "down".
The datetimepicker also has inbuilt validation.
"Chris" <Ch***@discussions.microsoft.comwrote in message
news:AD**********************************@microsof t.com...
I have VS 2005 (C#)
There is a control numericUpDown so you can spin numeric values. What I
need
to do is to spin date (+- one day). How to do that? Moreover, I want a
user
to type the date as well. So the control should validate the typed values
on
the fly. Is it possible?


Mar 13 '07 #3
Well I only pressed the datetimepicker to avoid having to write your own
logic for the textbox as that's more cumbersome.

If you hook up to the KeyPress or KeyUp event on the textbox you'll be able
to perform the validation during typing but remaining logic will be rather
complicated (e.g. to work out via the location of the focus and which part
of the date they're writing and then validate their input) .

What would be easier is to use the TextBox Enter and Leave events to
validate the date once they've finishing typing it. You could then validate
the date by calling DateTime.TryParse(). If the date is invalid put the
original value back into the textbox.

Failing that you could search on Google for such a control, perhaps someone
has already done all the work for you?

If you do end up writing the logic for the validation of the date in the
textbox.KeyPress or KeyUp event be sure to use DateTime.IsLeapYear for your
leap year validation.

HTH

Simon

"Chris" <Ch***@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
Is there a different way? I did it this way (but unfortunatelly without
letting user type the date). I put textbox (read only) and numericupdown
control. It works ok.
But how to validate (during typing) values typed (by a user) into the
textbox?
>

"Simon Tamman" wrote:
Yes.
Create a UserControl and add a datetimepicker and a button above and
below.
Hook up the buttons to an event and in the event set the "Value"
property of
the datetimepicker to the current Value.AddDay(1) or Value.AddDay(-1)
depending on if the button will make the date go up or down.
If you specify that the format used in the datetimepicker is "Custom"
then
you can specify a CustomFormat string, like "MM/dd/yy" for US time. The
user
will be able to type into this control although they will have to use
the
arrow keys to change which part of the date they are editing. A hidden
benefit is that they can also use the Arrow Up and Down keys to move the
selected part of the date "up" or "down".
The datetimepicker also has inbuilt validation.
"Chris" <Ch***@discussions.microsoft.comwrote in message
news:AD**********************************@microsof t.com...
I have VS 2005 (C#)
There is a control numericUpDown so you can spin numeric values. What
I
need
to do is to spin date (+- one day). How to do that? Moreover, I want a
user
to type the date as well. So the control should validate the typed
values
on
the fly. Is it possible?

Mar 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Larry R Harrison Jr | last post by:
I use the Lebans calendar control and love it; the only thing is that it commonly starts out at the year 1899 rather than the current year. Is there a way to specifically tell it to start at the...
2
by: Mark | last post by:
I have autorepeat turned on for a command button that increments the value in a textbox. When I click on the button and hold the mouse button down, the value in the textbox does not change. When I...
1
by: Ghost | last post by:
Hi all I hope in an answer that could help me about my problem. I'm creating a GUI in Visual C++ .NET and I'd like to split the "Spin Control" in two buttons, has someone some ideas to do this? ...
2
by: Drily Lit Raga | last post by:
VC++ calls this a spin control, I think VB calls it an updown? Anyway it is the control with two arrows on the right for entering numeric values. I have another text control that uses the spin...
6
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a...
10
by: sandraz444 | last post by:
I have an expression in the query under my form to autofill the date under a certain condition but it wont write to the underlying table?? The date shows in the form but not the table. Does anyone...
0
by: fredloh | last post by:
i have a tab control on my form. i then have several microsoft date and time picker control on the tab control. when i select a date on any of the date and time picker control, the result of the...
2
by: Unter | last post by:
Hi everyone - can someone tell me please how to get the NumericUpDown control to increase/decrease values quickly - by default it increases by the increment value and in VB6 we used to use code to...
4
by: Stewart Berman | last post by:
Is there a control equivalent to the old Spin control? The one with two hour heads and an optional textbox in the middle? The closest I can find is the NumericUpDown control and it's not the same...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.