rj tubera
rj tubera

Reputation: 757

Date Time Picker Manipulation

I have 2 dateTimePicker and 1 numericUpDown value.

I want to set my dateTimePicker1 my starting date. and whenever I increase the value of my numericUpdown it increments 1 day from the selected date in dateTimepicker1;

for ex. dateTimePicker1.Value = (feb 18, 2012 -user's choice) dateTimePicker2.Value (feb 18, 2012)

so if the user didn't increment the numericUpDownValue the DTP2 will be equalto DTP1

so if the user increased the numericUpdownValue (for ex 1, the DTP will be (feb 19, 2012));

here's what I've tried:

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            this.dateTimePicker1.MinDate = DateTime.Today.AddDays(1);
            this.dateTimePicker2.Value = dateTimePicker1.Value;

        }

 private void numericUpDown1_ValueChanged_1(object sender, EventArgs e)
        {

            int counter = Convert.ToInt16(numericUpDown1.Value + 1);
            this.dateTimePicker2.Value = DateTime.Now.AddDays(counter);
        }

I set the value of the dateTimePicker to 1 Day ahead of the day today.

This Code Gives me an error. Yeah I know it's incorrect but atleast I've tried. Anyone there who is willing to help? THANKS!

Upvotes: 1

Views: 1804

Answers (1)

Priyank
Priyank

Reputation: 1174

I have tried like this and it works perfect for me !!

Check it out below code:

    private void numericUpDown1_ValueChanged(object sender, EventArgs e)
    {
        dateTimePicker2.Value = dateTimePicker2.Value.AddDays(Convert.ToInt32(numericUpDown1.Value));

    }

Upvotes: 2

Related Questions