Answered by:
DATETIMEPICKER CHANGE TEXT

Question
-
Hi all
i'm using a DatetimePicker and I would like to change the its value as it was a textbox, i.e. without clicking on day then on month then on year
Is it possible
Tuesday, May 29, 2018 5:32 PM
Answers
-
i'm not using a textbox. I use the DTP
I would be able to change DTP value without clicking 3 times
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
VB Forums - moderator
- Marked as answer by Claudio111 Thursday, May 31, 2018 10:13 AM
Tuesday, May 29, 2018 6:24 PM
All replies
-
Hi
Then why use a DTP if you want to enter the DateTime via a TextBox? The whole point of using as DTP is to deal directly with the DateTime parts.
You could just replace the DTP with a TextBox and deal with the verification/formatting yourself, but a lot of code for little gain.
Regards Les, Livingston, Scotland
Tuesday, May 29, 2018 5:50 PM -
There is always the MaskedTextBox as shown below from this page.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.MaskedTextBox1.Mask = "00/00/0000" Me.MaskedTextBox1.ValidatingType = GetType(System.DateTime) Me.ToolTip1.IsBalloon = True End Sub Private Sub MaskedTextBox1_TypeValidationCompleted(ByVal sender As Object, ByVal e As TypeValidationEventArgs) Handles MaskedTextBox1.TypeValidationCompleted If (Not e.IsValidInput) Then Me.ToolTip1.ToolTipTitle = "Invalid Date" Me.ToolTip1.Show("The data you supplied must be a valid date in the format mm/dd/yyyy.", Me.MaskedTextBox1, 0, -20, 5000) Else ' Now that the type has passed basic type validation, enforce more specific type rules. Dim UserDate As DateTime = CDate(e.ReturnValue) If (UserDate < DateTime.Now) Then Me.ToolTip1.ToolTipTitle = "Invalid Date" Me.ToolTip1.Show("The date in this field must be greater than today's date.", Me.MaskedTextBox1, 0, -20, 5000) e.Cancel = True End If End If End Sub ' Hide the tooltip if the user starts typing again before the five-second display limit on the tooltip expires. Private Sub MaskedTextBox1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MaskedTextBox1.KeyDown Me.ToolTip1.Hide(Me.MaskedTextBox1) End Sub
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
VB Forums - moderator
- Marked as answer by Claudio111 Tuesday, May 29, 2018 6:21 PM
- Unmarked as answer by Claudio111 Tuesday, May 29, 2018 6:22 PM
Tuesday, May 29, 2018 5:54 PM -
Hi all
i'm using a DatetimePicker and I would like to change the its value as it was a textbox, i.e. without clicking on day then on month then on year
Is it possible
Can't you use DateTimePicker.Value ?
like for example
DatetimePicker.Value = New DateTime(2017, 10, 16)
Tuesday, May 29, 2018 6:12 PM -
i'm not using a textbox. I use the DTP
I would be able to change DTP value without clicking 3 times
Tuesday, May 29, 2018 6:22 PM -
i'm not using a textbox. I use the DTP
I would be able to change DTP value without clicking 3 times
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
VB Forums - moderator
- Marked as answer by Claudio111 Thursday, May 31, 2018 10:13 AM
Tuesday, May 29, 2018 6:24 PM -
i'm not using a textbox. I use the DTP
I would be able to change DTP value without clicking 3 times
Hi
Use the drop down calendar - that is what it is for!
Regards Les, Livingston, Scotland
Tuesday, May 29, 2018 6:39 PM -
No
Success
CorTuesday, May 29, 2018 7:03 PM -
No
Which?
Success
CorRegards Les, Livingston, Scotland
Tuesday, May 29, 2018 7:04 PM -
It is not possible to use the DateTimePicker as it was a textbox to enter a date. That was the question and I thought I gave the only possible answer.
Success
CorTuesday, May 29, 2018 7:11 PM -
You could just use an InputBox or make your own input form to show:
Private Sub DateTimePicker1_MouseDown(sender As Object, e As MouseEventArgs) Handles DateTimePicker1.MouseDown Dim dateText = InputBox("Enter a date:", "Set Date", DateTimePicker1.Value.ToShortDateString) If Not Date.TryParse(dateText, DateTimePicker1.Value) Then MessageBox.Show("The text provided could not be interpreted as a date", "Invalid Date Value", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End Sub
But as Cor said, there is no way to do it with just the DateTimePicker's default functionality.Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
Tuesday, May 29, 2018 8:15 PM -
Hi all
i'm using a DatetimePicker and I would like to change the its value as it was a textbox, i.e. without clicking on day then on month then on year
Is it possible
If the user enters two digits for month and day, and four for year this will produce the desired result I believe.
Public Class Form1 Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown DateTimePicker1.CustomFormat = "MM/dd/yyyy" DateTimePicker1.Format = DateTimePickerFormat.Custom End Sub Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged SendKeys.Send(".") End Sub End Class
"Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it."
- from former MSDN User JohnWein
Tuesday, May 29, 2018 9:08 PM -
Hi all
i'm using a DatetimePicker and I would like to change the its value as it was a textbox, i.e. without clicking on day then on month then on year
Is it possible
I don't believe you could create a custom control inheriting DateTimePicker and perform that. Nor does it make sense really.La vida loca
Tuesday, May 29, 2018 9:24 PM -
i'm using a DatetimePicker and I would like to change the its value as it was a textbox, i.e. without clicking on day then on month then on year
Is it possible
- Edited by Castorix31 Tuesday, May 29, 2018 9:40 PM
Tuesday, May 29, 2018 9:39 PM