chris
chris

Reputation: 161

Datetimepicker two options select date from dropdown or manualy ovewrite

I'm making a datetimepicker which can save the date by selecting a "pay" date from a dropdown menu and it also should be enable to save the date by manualy clicking a date on the calandar and after that it will be saved in a db. The manual option always has to override the dates from the dropdown.

But here is the problem, I have no idea how to make the Onclick function if this is even possible in a datetimepicker. So far the dropdown options always overwrite the manualy selected date which i dont want it to do.

 dateTimePicker1.Value = DateTime.Now.AddDays(1);
 MessageBox.Show(dateTimePicker1.Value.ToString());

Anyone has a good idea?

(dropdown code:)

The dropdown code is in dutch sorry, In the dropdown menu u have 4 options (like +14 days +7 days) resdatum means how many days it has to go up. Factuur datum means the start date and betaaldatum basicly is the start date + the amount of days from resdatum.

Locatie_reservering lr = new Locatie_reservering();
            string ResDatum = lr.getFirstDate(reservering.getID());
            DateTime FactuurDatum = betalingsConditie.BerekenFactuurdatum(cbBetalingsConditie.SelectedValue.ToString(), ResDatum);
            DateTime BetaalDatum = betalingsConditie.BerekenBetaaldatum(cbBetalingsConditie.SelectedValue.ToString(), FactuurDatum, ResDatum);
            dateTimePicker1.Value = BetaalDatum;

Upvotes: 1

Views: 503

Answers (2)

m_d_p29
m_d_p29

Reputation: 163

Try using the datetimepicker's ValueChanged event. This will be fired whenever the datetime is changed.

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
  textBox1.Text = dateTimePicker1.Value.ToShortDateString();
}

Upvotes: 0

Vano Maisuradze
Vano Maisuradze

Reputation: 5909

You can use MouseUp event:

    private void dateTimePicker1_MouseUp(object sender, MouseEventArgs e)
    {
        dateTimePicker1.Value = DateTime.Now.AddDays(1);
        MessageBox.Show(dateTimePicker1.Value.ToString());
    }

Upvotes: 1

Related Questions