473,418 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

MonthCalendar DateChanged event problem

DS
I seem to have stumbled upon something that I can't explain and was
wondering if someone else could maybe help me figure out why this
happens. I've tried it in both VS2003 and with VS2005b2 and in both
cases the result is the same: an ArgumentOutOfRangeException.

Add the following to a blank WindowsForm in C# then call doStuff() from
the constructor or a buttonClick event. If you click on any date, it
pops up a messageBox (as it should) telling you the new date. Great. Now
try clicking one of the buttons to goto the next or previous month. At
first one messageBox shows up telling you the selection has changed to
the first of the next (or previous month), then when you click ok, it
seems to go haywire. It flips through about 19 months before crashing.
This is especially weird since it should only flip 1 month
(scrollChange=1). Changing the scrollChange has no effect, it just flips
through about 19 iterations of whatever scrollChange is set to. Ideas?

Thanks in advance,
-DS
---- Code below ----

private void doStuff()
{
MonthCalendar mc = new MonthCalendar();
mc.CalendarDimensions = new Size(1,1);
mc.Location = new Point(50, 50);
mc.MaxSelectionCount = 1;
mc.SetDate(DateTime.Parse("1 January 2005"));
mc.ScrollChange = 1;
this.Controls.Add(mc);
mc.DateChanged += new DateRangeEventHandler(mc_DateChanged);
}

void mc_DateChanged(object sender, DateRangeEventArgs e)
{
MessageBox.Show("date changed " + e.Start.ToString());
}
Nov 24 '05 #1
3 6278
DS
DS wrote:
I seem to have stumbled upon something that I can't explain and was
wondering if someone else could maybe help me figure out why this
happens. I've tried it in both VS2003 and with VS2005b2 and in both
cases the result is the same: an ArgumentOutOfRangeException.

Add the following to a blank WindowsForm in C# then call doStuff() from
the constructor or a buttonClick event. If you click on any date, it
pops up a messageBox (as it should) telling you the new date. Great. Now
try clicking one of the buttons to goto the next or previous month. At
first one messageBox shows up telling you the selection has changed to
the first of the next (or previous month), then when you click ok, it
seems to go haywire. It flips through about 19 months before crashing.
This is especially weird since it should only flip 1 month
(scrollChange=1). Changing the scrollChange has no effect, it just flips
through about 19 iterations of whatever scrollChange is set to. Ideas?

Thanks in advance,
-DS
---- Code below ----

private void doStuff()
{
MonthCalendar mc = new MonthCalendar();
mc.CalendarDimensions = new Size(1,1);
mc.Location = new Point(50, 50);
mc.MaxSelectionCount = 1;
mc.SetDate(DateTime.Parse("1 January 2005"));
mc.ScrollChange = 1;
this.Controls.Add(mc);
mc.DateChanged += new DateRangeEventHandler(mc_DateChanged);
}

void mc_DateChanged(object sender, DateRangeEventArgs e)
{
MessageBox.Show("date changed " + e.Start.ToString());
}


I forgot to add that I believe I need to use the DateChanged event as
opposed to the DateSelected because I need to get keyboard changes as
well. Unfortunately DateSelected is only fired by mouse clicks whereas
DateChanged fires from both.
Nov 24 '05 #2
It sounds like a bug of .NET. It does not happen if you do not show a
modal dialog in the event handler - in that case the event is fired
just twice!

That problem only happens if you change months by clicking one of the
arrow buttons. In other cases, the event is fired at most twice.

Nov 24 '05 #3
DS
Truong Hong Thi wrote:
It sounds like a bug of .NET. It does not happen if you do not show a
modal dialog in the event handler - in that case the event is fired
just twice!

That problem only happens if you change months by clicking one of the
arrow buttons. In other cases, the event is fired at most twice.


Hi Truong, thanks fro the feedback. Its nice to know that someone else
ran into a similar problem. I tried wiring it up to a multiline textbox
and had mixed results. If there was no '\r\n' in the string it would
crash, yet if it had the linefeed/cr after the date it didn't crash. Not
reliable enough for my liking.

Another problem that others seem to have run into with the DateChanged
event is that every minute or so it seems to fire (probably because of
the system clock or something), and this is just plain bad. I think I'll
just forgo DateChanged and use DateSelected instead-- it seems to have
less baggage. Only thing is that keyboard support is nixed since it only
fires on a mouse click event.

-DS
Nov 29 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert Misiak | last post by:
When using a MonthCalendar.DateChanged eventhandler, is there a way a clean way to figure out if the date was changed by the user (as opposed to it being changed programmatically)? Thanks,...
4
by: @piranha | last post by:
hi, i have an application with a montcalendar and a datagrid when someone selects a new date the datagrid is refilled with the right data. now i remarked the data in the grid refreshes sometimes...
13
by: steven | last post by:
A monthcalendar checks every 2 minutes if theres a new day. Does anyone knows how to disable this ? The problem is that, everytime a monthcalendar checks this, the form where the monhcalendar is...
0
by: steven | last post by:
Start a new project with 2 forms: one with a datagrid, a button and a monthcalendar, and another form without controls. Try this code in your form with the monthcalendar: Private Sub...
8
by: vbmark | last post by:
I want the MonthCalendar control to return the single day selected. I have MaxSelectionCount = 1. What I get back though is this: "SelectionRange: Start: 5/5/2005 12:00:00 AM, End: 5/5/2005...
2
by: meska | last post by:
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...
0
by: mtczx232 | last post by:
before we discuss about the problem: 1.it's pity that microsoft not supply event that occur only when Today is change. 2. it's not clear for what have DateSelected event. why I need to deal with...
5
by: Randy | last post by:
Based on the date that the user selects, I'm trying to make the MonthCalendar control highlight the entire week. In my case, the week is from Monday - Sunday. I thought that using AddBoldedDate...
11
by: Randy | last post by:
I have a MonthCalendar on one of my forms. I have disovered that the DateChanged event is triggered not only when the user clicks on a new date, but also if they click on the Previous or Next...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.