2009-01-19 Carlos Alberto Cortez <calberto.cortez@gmail.com>
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>
Mon, 19 Jan 2009 15:09:59 +0000 (15:09 -0000)
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>
Mon, 19 Jan 2009 15:09:59 +0000 (15:09 -0000)
* 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

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/MonthCalendar.cs

index c99caba252422e2257249c325210ba4ce7890dbe..9baf838d453af3840333a6e46ea82af6c4b7e144 100644 (file)
@@ -1,3 +1,13 @@
+2009-01-19  Carlos Alberto Cortez <calberto.cortez@gmail.com>
+
+       * 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 <calberto.cortez@gmail.com> 
 
        * MonthCalendar.cs: Remove the extra OnDateChanged call when handling
index 9a9b767b548ce336c767b5be1fcc96a94aabe6f4..9e4898f2b7a38277906666cdaf8ac834a8a20f12 100644 (file)
@@ -1626,8 +1626,9 @@ namespace System.Windows.Forms {
                // 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 @@ namespace System.Windows.Forms {
                                                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