Click here to Skip to main content
16,022,542 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All, I really need help with my problem I want to Change textbox entered value to the exact month for example:

TextBox.Text = "1", when enter this should change DateTimePicker to ="01/01/2018".
for other months
TextBox.Text = "2", when enter this should change DateTimePicker to ="01/02/2018".

until
TextBox.Text = "12", when enter this should change DateTimePicker to ="01/12/2018".

What I have tried:

Dear All, I really need help with my problem I want to Change textbox entered value to the exact month for example:

TextBox.Text = "1", when enter this should change DateTimePicker to ="01/01/2018".
for other months
TextBox.Text = "2", when enter this should change DateTimePicker to ="01/02/2018".

until
TextBox.Text = "12", when enter this should change DateTimePicker to ="01/12/2018".
Posted
Updated 5-May-18 5:01am

1 solution

Try this:
private void myTextBox_TextChanged(object sender, EventArgs e)
    {
    int month;
    if (int.TryParse(myTextBox.Text, out month))
        {
        DateTime dt = myDateTimePicker.Value;
        myDateTimePicker.Value = dt.AddMonths(month - dt.Month);
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900