Prashant More

Prashant More

  • NA
  • 66
  • 1.1k

i want some date disable after select in datetimepicker

Mar 17 2016 2:53 AM
{
DateTime lastDate;
System.Text.RegularExpressions.Regex rg;
bool valueChangingProgramatically = false;
public Form4()
{
InitializeComponent();
}
private void Form4_Load(object sender, EventArgs e)
{
dateTimePicker1.CustomFormat = "yyyy";
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker2.MinDate = DateTime.Now.Date;
//Max Date will restrict the user to select future dates than the specified date
dateTimePicker2.MaxDate = DateTime.Now.AddDays(30).Date; ;
}
private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
{
}
private void dateTimePicker3_ValueChanged(object sender, EventArgs e)
{
dateTimePicker3.ValueChanged += new EventHandler(dateTimePicker3_ValueChanged);
if (!valueChangingProgramatically)
{
if (rg.IsMatch(dateTimePicker3.Value.ToLongDateString()))
{
valueChangingProgramatically = true;
if (lastDate < dateTimePicker3.Value)
dateTimePicker3.Value = dateTimePicker3.Value.AddDays(1);
else
dateTimePicker3.Value = dateTimePicker3.Value.AddDays(-1);
}
}
else
valueChangingProgramatically = false;
lastDate = dateTimePicker3.Value;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string fff = comboBox1.SelectedItem.ToString(); //not working
textBox1.Text = fff;
MessageBox.Show("ddddddddd", textBox1.Text);
lastDate = dateTimePicker3.Value;
rg = new System.Text.RegularExpressions.Regex(fff);
if (lastDate < dateTimePicker3.Value)
dateTimePicker3.Value = dateTimePicker3.Value.AddDays(1);
}

Answers (3)