Obwohl ich glaube, Ihr Service Duration
ein combobox
ist, habe ich noch textbox
wie pro Ihre Frage verwendet.
Anruf textchanged
. Wenn der Text in Text ändert, wird die Zeit hinzugefügt dateTimePicker2
private void textBox1_TextChanged(object sender, EventArgs e)
{
int mins = Convert.ToInt32(textBox1.Text);
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(mins);
}
Für Combobox, rufen auch textchanged
.
private void comboBox1_TextChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == -1 || comboBox1.Text == null)
{
dateTimePicker2.Value = dateTimePicker1.Value;
}
else if (comboBox1.Text == "15")
{
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(15);
}
else if (comboBox1.Text == "30")
{
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(30);
}
else if (comboBox1.Text == "60")
{
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(60);
}
}
Sie haben Recht, es ist eine ComboBox mein Fehler. Ich habe deine Antwort implementiert, aber es scheint aus irgendeinem Grund nicht zu funktionieren. Heir ist, wie ich es tat: private void cmbDuration_TextChanged (object sender, EventArgs e) { if (cmbDuration.SelectedIndex == -1 || cmbDuration.Text == null) { dtpEntry1.Value = dtpEntry.Value; } – Anothando
if (cmbDuration.Text == "15") { dtpEntry1.Value = dtpEntry.Value.AddMinutes (15); } sonst if (cmbDuration.Text == "30") { dtpEntry1.Value = dtpEntry.Value.AddMinutes (30); } sonst if (cmbDuration.Text == "60") { dtpEntry1.Value = dtpEntry.Value.AddMinutes (60); } } – Anothando
@Anothando irgendein Fehler gezeigt? – active92