Question datetimepick gets the date format and places it in a textbox

manny cash

Member
Joined
Oct 19, 2024
Messages
18
Programming Experience
Beginner
This little code does not transfer the date to my text box, something is missing, or any declaration, or something wrong like that? Please, I need a hand.
I need to format the date.
VB.NET:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    txtAppoDate.Text = DateTimePicker1.Value.ToString()
End Sub
Thank you, guy, I have never worked with datetimepicker. Have a nice day
 
Last edited by a moderator:
Solution
Yes it does. What's probably happening is that that code isn't even being executed. Did you actually check that? I'd wager not. There is no Handles clause on that method, so it's not handling any event my default. If you haven't used an AddHandler statement anywhere, it's not handling an event at all. Normally, you'd expect that declaration to look like this:
VB.NET:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
The question is, why doesn't it? It almost certainly would have if you created the control and the event handloer in the usual way, so you must have removed it at some point. Did you cut and paste that control in the designer at some point? That would have done it...
Yes it does. What's probably happening is that that code isn't even being executed. Did you actually check that? I'd wager not. There is no Handles clause on that method, so it's not handling any event my default. If you haven't used an AddHandler statement anywhere, it's not handling an event at all. Normally, you'd expect that declaration to look like this:
VB.NET:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
The question is, why doesn't it? It almost certainly would have if you created the control and the event handloer in the usual way, so you must have removed it at some point. Did you cut and paste that control in the designer at some point? That would have done it. Cutting effectively deletes the control, so it deletes any Handles clauses for that control. Pasting does not restore the Handles clauses.
 
Solution
For future reference, please select "Question" as the title prefix when creating a new thread to ask a question. When the issue is resolved, you can then click 'Resolved' above the first post to change that to "Resolved". Those prefixes help everyone quickly identify the state of each thread in a list, so they don't have to open and read everything. If a particular post resolves the issue, you should also mark that post as the solution on the right-hand side. That will reproduce that post right under the question, so anyone with a similar problem in future can quickly see how to solve it.. I've done all that for you this time.
 
Back
Top