Event: raised by user action or application code?

  • Thread starter Thread starter Daan
  • Start date Start date
D

Daan

I have a dateTimePicker with a ValueChanged event handler attached.
But I only want to execute the event handling code if the USER has
changed the value of the picker and not if my own application code
ajusts the value of the dateTimePicker. How can I discriminate where
the event came from? Perhaps I can use the sender or EventArgs for
that, but I cannot find how. Any suggestions?
 
I have a dateTimePicker with a ValueChanged event handler attached.
But I only want to execute the event handling code if the USER has
changed the value of the picker and not if my own application code
ajusts the value of the dateTimePicker. How can I discriminate where
the event came from? Perhaps I can use the sender or EventArgs for
that, but I cannot find how. Any suggestions?

I have figured out a workaround that makes sure the event is not
handled when the value is updated by my own code: first remove the
attached event handler, than update the value of the dateTimePicker,
then re-attach the event handler. It works, but I still wonder if
there is a better solution.
 
Before you modify the value in code either detach the event handler and
reattach when you're done or set a boolean flag that the handler looks at
before acting.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
Back
Top