user153923
user153923

Reputation:

DateTime Control ValueChanged Event, C#

I've got an SQL Query that runs when someone changes the Date on the DateTime Control on my Windows Form.

The Query is (currently) fired whenever the DateTime Control's ValueChanged property is fired.

This works poorly because:

  1. If someone is trying to use the Control's scroll feature to go from January back to last September, the ValueChanged event fires once for each month (makes the GUI slow and makes unnecessary SQL calls).

  2. If someone manually updates the date by typing the value into the text box, the ValueChanged property does not fire.

I can not use the Control's CloseUp property to solve #1 because then #2 would not fire.

A TextChanged property would be nice, but the DateTime Control does not expose one of those properties.

What is the best way to tell when my date has really been changed? (I'm not adding a timer that polls the form, either)

Development Environment: VS2008
Framework: 3.5
Language: C#
Target: Windows PC

Upvotes: 2

Views: 872

Answers (1)

Hans Passant
Hans Passant

Reputation: 941455

(I'm not adding a timer that polls the form, either)

You exclude the one thing you should do to solve this problem. Then again, you wouldn't use a timer to poll the form, you start one in the DataChanged event handler. The Tick event handler disables the timer and runs the query. Make it a second or so. Add a button if you think that slows down the user too much.

A distant second choice could be an asynchronous query that you can cancel. Like SqlCommand.BeginExecuteXxxx(). Works well for the UI, not so well for the dbase server load.

Upvotes: 1

Related Questions