MonthCalendar and DateChanged + DateSelected events

M

meska

Hi all,

Scenario:

I have a MonthCalendar control, and DataGridView. Depending on dates
displayed in MonthCalendar I want to update information from database.

The Possible Solution:

So I must use DateChanged and/or DateSelected events to get the new dates
and update info from the database. Let’s say the implementation is simple:
in these events I call a function passing the SelectionStart and
SelectionEnd which updates the database.

The problem:

Let's say I use DateChanged event. If user uses the navigation buttons and
navigates from one month to other, the DateChanged event is fired two times
(in our scenario - two calls to the database)

If the user decides to select dates with the mouse by simply dragging
through them. Let's say he starts at 05.15 and ends at 05.19 day. DataChange
event is fired 5 times (in our scenario - five calls to the database)

So we are wasting database resources.

If I try to use the DateSelected event, things are better, the event is
fired one time if the date is selected, but event isn't fired at all if user
uses buttons for navigation

Any ideas?
 
C

Chris Jobson

meska said:
Hi all,

Scenario:

I have a MonthCalendar control, and DataGridView. Depending on dates
displayed in MonthCalendar I want to update information from database.

The Possible Solution:

So I must use DateChanged and/or DateSelected events to get the new dates
and update info from the database. Let's say the implementation is simple:
in these events I call a function passing the SelectionStart and
SelectionEnd which updates the database.

The problem:

Let's say I use DateChanged event. If user uses the navigation buttons and
navigates from one month to other, the DateChanged event is fired two
times
(in our scenario - two calls to the database)

If the user decides to select dates with the mouse by simply dragging
through them. Let's say he starts at 05.15 and ends at 05.19 day.
DataChange
event is fired 5 times (in our scenario - five calls to the database)

So we are wasting database resources.

If I try to use the DateSelected event, things are better, the event is
fired one time if the date is selected, but event isn't fired at all if
user
uses buttons for navigation

Any ideas?

It seems to me that what you want is to update the database when the user
FINISHES doing things on the MonthCalendar. Some ideas for this are:
- provide an explicit way for the user to indicate this, e.g. an "Update
Now" button;
- update the databse when the user moves away from the Monthcalendar,
perhaps by handling the Validating event;
- update the database when no changes happen on the MonthCalendar for a few
seconds (start a timer whenever the DateChanged event is fired (first
cancelling the timer if it's already going), then update the database when
the timer expires).

Hope this helps.
Chris Jobson
 
C

Chris Jobson

meska said:
Hi all,

Scenario:

I have a MonthCalendar control, and DataGridView. Depending on dates
displayed in MonthCalendar I want to update information from database.

The Possible Solution:

So I must use DateChanged and/or DateSelected events to get the new dates
and update info from the database. Let's say the implementation is simple:
in these events I call a function passing the SelectionStart and
SelectionEnd which updates the database.

The problem:

Let's say I use DateChanged event. If user uses the navigation buttons and
navigates from one month to other, the DateChanged event is fired two
times
(in our scenario - two calls to the database)

If the user decides to select dates with the mouse by simply dragging
through them. Let's say he starts at 05.15 and ends at 05.19 day.
DataChange
event is fired 5 times (in our scenario - five calls to the database)

So we are wasting database resources.

If I try to use the DateSelected event, things are better, the event is
fired one time if the date is selected, but event isn't fired at all if
user
uses buttons for navigation

Any ideas?

It seems to me that what you want is to update the database when the user
FINISHES doing things on the MonthCalendar. Some ideas for this are:
- provide an explicit way for the user to indicate this, e.g. an "Update
Now" button;
- update the databse when the user moves away from the Monthcalendar,
perhaps by handling the Validating event;
- update the database when no changes happen on the MonthCalendar for a few
seconds (start a timer whenever the DateChanged event is fired (first
cancelling the timer if it's already going), then update the database when
the timer expires).

Hope this helps.
Chris Jobson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top