Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There are two events. One is ValueChanged and another one is TextChanged

If value is changed then I can do something that is my need actually

But following two conditions getting same error

How to know the value is changed or not?

C#
if (datetimepicker.ValueChanged == true)
       {
          strMonthCode = "JAN";
        }
      else if (datetimepicker.TextChanged == true)
        {
          strMonthCode = "FEB";
        }


In both cases I am getting an error
Posted
Updated 14-May-13 2:23am
v4
Comments
ZurdoDev 14-May-13 8:12am    
I'm confused. You said that you can use the ValueChanged event but you don't know how to tell when the value has changed? Please explain.
Balu Balaji 14-May-13 8:16am    
i just want to check DateTimePicker value is changed or not?

suppose for example radiobutton.checked==true
then
do this

like this i need now what i need to do?
Basmeh Awad 14-May-13 8:19am    
why are you checking it again
if (datetimepicker.ValueChanged == true)
obviously your date has changed thats why the event gets activated..directly do what you want...
strMonthCode = "JAN"; on valueChange event

1 solution

You can't use them like that. They're events - not properties. You need to add an eventhandler. Something like:

C#
public partial class Form1 : Form
{
    private bool dateChanged = false;

    private void Form1_Load(object sender, EventArgs e)
    {
        dateTimePicker1.ValueChanged += new System.EventHandler(dateTimePicker1_ValueChanged);
    }

    private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
    {
        dateChanged = true;
        //Here you can do stuff that needs to be done when the value changes
    }

    private void button1_Click(object sender, EventArgs e)
    {
        //Example: Here you can check if the value has changed since you opened the form:
        if (dateChanged)
        {
            //The date has been changed - do what I need to do
        }
    }
}
 
Share this answer
 
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900