From 2501c05951b0194b2f1b4a094cd14132668771cd Mon Sep 17 00:00:00 2001 From: Carlos Alberto Cortez Date: Mon, 19 Jan 2009 15:09:59 +0000 Subject: [PATCH] 2009-01-19 Carlos Alberto Cortez * MonthCalendar.cs: When handling the selection changes using the mouse, don't set SelectionRange if the selection range didn't actually change. This matters because, even if we set the range to the same previous range, an extra DateChanged event is fired. Just to be clear: SelectionRage property doesn't check whether the new value is different to the previous one (by ref equals doesn't work here). Fixes other bits of #364914. svn path=/trunk/mcs/; revision=123799 --- .../System.Windows.Forms/ChangeLog | 10 ++++++++++ .../System.Windows.Forms/MonthCalendar.cs | 10 +++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog index c99caba252422..9baf838d453af 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog @@ -1,3 +1,13 @@ +2009-01-19 Carlos Alberto Cortez + + * MonthCalendar.cs: When handling the selection changes using the + mouse, don't set SelectionRange if the selection range didn't actually + change. This matters because, even if we set the range to the same + previous range, an extra DateChanged event is fired. Just to be clear: + SelectionRage property doesn't check whether the new value is + different to the previous one (by ref equals doesn't work here). + Fixes other bits of #364914. + 2009-01-19 Carlos Alberto Cortez * MonthCalendar.cs: Remove the extra OnDateChanged call when handling diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MonthCalendar.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MonthCalendar.cs index 9a9b767b548ce..9e4898f2b7a38 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MonthCalendar.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MonthCalendar.cs @@ -1626,8 +1626,9 @@ private void AddTimeToSelection (int delta, bool isDays) // attempts to add the date to the selection without throwing exception private void SelectDate (DateTime date) { // try and add the new date to the selction range + SelectionRange range = null; if (is_shift_pressed || (click_state [0])) { - SelectionRange range = new SelectionRange (first_select_start_date, date); + range = new SelectionRange (first_select_start_date, date); if (range.Start.AddDays (MaxSelectionCount-1) < range.End) { // okay the date is beyond what is allowed, lets set the maximum we can if (range.Start != first_select_start_date) { @@ -1636,13 +1637,16 @@ private void AddTimeToSelection (int delta, bool isDays) range.End = range.Start.AddDays (MaxSelectionCount-1); } } - SelectionRange = range; } else { if (date >= MinDate && date <= MaxDate) { - SelectionRange = new SelectionRange (date, date); + range = new SelectionRange (date, date); first_select_start_date = date; } } + + // Only set if we re actually getting a different range (avoid an extra DateChanged event) + if (range != null && range.Start != selection_range.Start || range.End != selection_range.End) + SelectionRange = range; } // gets the week of the year