开发者

checking value changed or not in datetimepicker

I have 2 datetimepicker on form having joining and leaving date ,if i dont change these values than it throws exception on total_button_click,since its default value is today's date ,so i want to enable total_button only when datetimepicker value gets changed,can i use any property of datetimepicker for this purpose ,below is the code for total_button

private void Total_button_Click(object sender, EventArgs e)
{
    int remain, re, d, r;
    string oday;                
    decimal sum = dataGridView1.Rows.OfType<DataGridViewRow>()
            .Sum(row =>开发者_StackOverflow社区 Convert.ToDecimal(row.Cells["Money"].Value));

    // total amnt drawn
    textBox1.Text = sum.ToString();
    d = int.Parse(textBox3.Text);
    int div = d / 30;

    // 1 day payment
    oday = div.ToString();
    textBox6.Text = (dateTimePicker2.Value - dateTimePicker1.Value).TotalDays.ToString("#");
    re = int.Parse(textBox6.Text) * int.Parse(oday);

    // total  days paymnt
    textBox7.Text = re.ToString();
    r = int.Parse(textBox7.Text) - int.Parse(textBox1.Text);

    // total payment -drawn i.e to b payed                
    textBox8.Text = r.ToString();
}


Use the DateTimePickerEvent ValueChanged http://msdn.microsoft.com/de-de/library/system.windows.forms.datetimepicker.valuechanged.aspx . If the event gets invoked, you can enable your button.


To get this working you would need the ValueChanged event of the datetimepicker

dateTimePicker1.ValueChanged += new EventHandler(dateTimePicker1_ValueChanged);

Now this would fire in general even if you select the current date from the Calender displayed, to avoid that set the format to only Date and avoid the time component like

dateTimePicker1.Value = DateTime.Today;

Now this would fire only if you change the date and within this you can enable your required button

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜