diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/GridEntry.GridEntryAccessibleObject.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/GridEntry.GridEntryAccessibleObject.cs index 12b671e5668..ca9257dbcd7 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/GridEntry.GridEntryAccessibleObject.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/GridEntry.GridEntryAccessibleObject.cs @@ -410,7 +410,10 @@ internal override void SetFocus() base.SetFocus(); - RaiseAutomationEvent(UIA_EVENT_ID.UIA_AutomationFocusChangedEventId); + if (!PropertyGridView.InPropertySet && !PropertyGridView.EditMouseDown) + { + RaiseAutomationEvent(UIA_EVENT_ID.UIA_AutomationFocusChangedEventId); + } } } } diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/PropertyGridView.Flags.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/PropertyGridView.Flags.cs index a02f11f883f..2f0dfa6d9ba 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/PropertyGridView.Flags.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/PropertyGridView.Flags.cs @@ -22,6 +22,7 @@ private enum Flags : ushort /// ButtonLaunchedEditor = 0x0100, NoDefault = 0x0200, - ResizableDropDown = 0x0400 + ResizableDropDown = 0x0400, + EditMouseDown = 0x0800 } } diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/PropertyGridView.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/PropertyGridView.cs index dcdb7878659..9ed2d3031e6 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/PropertyGridView.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/PropertyGridView.cs @@ -2566,44 +2566,59 @@ private void OnEditLostFocus(object? sender, EventArgs e) InvokeLostFocus(this, EventArgs.Empty); } - private void OnEditMouseDown(object? sender, MouseEventArgs e) + internal bool EditMouseDown { - if (!FocusInside) - { - SelectGridEntry(_selectedGridEntry, pageIn: false); - } - - if (e.Clicks % 2 == 0) - { - DoubleClickRow(_selectedRow, toggleExpand: false, RowValue); - EditTextBox.SelectAll(); - } + get => _flags.HasFlag(Flags.EditMouseDown); + private set => SetFlag(Flags.EditMouseDown, value); + } - if (_rowSelectTime == 0) + private void OnEditMouseDown(object? sender, MouseEventArgs e) + { + try { - return; - } - - // Check if the click happened within the double click time since the row was selected. - // This allows the edits to be selected with two clicks instead of 3 (select row, double click). - long timeStamp = DateTime.Now.Ticks; - int delta = (int)((timeStamp - _rowSelectTime) / 10000); // make it milliseconds + EditMouseDown = true; - if (delta < SystemInformation.DoubleClickTime) - { - Point screenPoint = EditTextBox.PointToScreen(e.Location); + if (!FocusInside) + { + SelectGridEntry(_selectedGridEntry, pageIn: false); + } - if (Math.Abs(screenPoint.X - _rowSelectPos.X) < SystemInformation.DoubleClickSize.Width && - Math.Abs(screenPoint.Y - _rowSelectPos.Y) < SystemInformation.DoubleClickSize.Height) + if (e.Clicks % 2 == 0) { DoubleClickRow(_selectedRow, toggleExpand: false, RowValue); - PInvokeCore.SendMessage(EditTextBox, PInvokeCore.WM_LBUTTONUP, (WPARAM)0, (LPARAM)e.Location); EditTextBox.SelectAll(); } - _rowSelectPos = Point.Empty; + if (_rowSelectTime == 0) + { + return; + } - _rowSelectTime = 0; + // Check if the click happened within the double click time since the row was selected. + // This allows the edits to be selected with two clicks instead of 3 (select row, double click). + long timeStamp = DateTime.Now.Ticks; + int delta = (int)((timeStamp - _rowSelectTime) / 10000); // make it milliseconds + + if (delta < SystemInformation.DoubleClickTime) + { + Point screenPoint = EditTextBox.PointToScreen(e.Location); + + if (Math.Abs(screenPoint.X - _rowSelectPos.X) < SystemInformation.DoubleClickSize.Width && + Math.Abs(screenPoint.Y - _rowSelectPos.Y) < SystemInformation.DoubleClickSize.Height) + { + DoubleClickRow(_selectedRow, toggleExpand: false, RowValue); + PInvokeCore.SendMessage(EditTextBox, PInvokeCore.WM_LBUTTONUP, (WPARAM)0, (LPARAM)e.Location); + EditTextBox.SelectAll(); + } + + _rowSelectPos = Point.Empty; + + _rowSelectTime = 0; + } + } + finally + { + EditMouseDown = false; } } @@ -3992,7 +4007,7 @@ private void Refresh(bool fullRefresh, int startRow, int endRow) startRow = 0; } - if (OwnerGrid.HavePropertyEntriesChanged()) + if (fullRefresh || OwnerGrid.HavePropertyEntriesChanged()) { if (HasEntries && !InPropertySet && !CommitEditTextBox()) { diff --git a/src/test/unit/System.Windows.Forms/System/Windows/Forms/PropertyGridTests.cs b/src/test/unit/System.Windows.Forms/System/Windows/Forms/PropertyGridTests.cs index 9d1c5bc99e7..4c25bb38e70 100644 --- a/src/test/unit/System.Windows.Forms/System/Windows/Forms/PropertyGridTests.cs +++ b/src/test/unit/System.Windows.Forms/System/Windows/Forms/PropertyGridTests.cs @@ -4124,6 +4124,63 @@ public void PropertyGrid_SelectedGridItemChanged_TriggeredCorrectly() eventArgs.NewSelection.Should().Be(gridItem); } + // Regression test for https://github.com/dotnet/winforms/issues/13071 + [WinFormsFact] + public void PropertyGrid_FullRefreshShouldTriggerTypeConverterGetProperties() + { + using PropertyGrid propertyGrid = new() + { + SelectedObject = new SelectedObject() + }; + PropertyGridView propertyGridView = propertyGrid.TestAccessor().Dynamic._gridView; + + MyTypeConverter.GetPropertiesInvokeCount = 0; + propertyGridView.Refresh(true); + + int getPropertiesInvokeCount2 = MyTypeConverter.GetPropertiesInvokeCount; + getPropertiesInvokeCount2.Should().Be(1); + } + + #region classes used for PropertyGrid_FullRefreshShouldTriggerTypeConverterGetProperties + [TypeConverter(typeof(MyTypeConverter))] + private class SelectedObject + { + private string _a; + private string _b; + + [RefreshProperties(RefreshProperties.All)] + public string A + { + get { return _a; } + set { _a = value; } + } + + public string B + { + get { return _b; } + set { _b = value; } + } + } + + private class MyTypeConverter : TypeConverter + { + public static int GetPropertiesInvokeCount { get; set; } + public MyTypeConverter() + : base() { } + + public override bool GetPropertiesSupported(ITypeDescriptorContext context) + { + return true; + } + + public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) + { + GetPropertiesInvokeCount++; + return base.GetProperties(context, value, attributes) ?? TypeDescriptor.GetProperties(value, attributes); + } + } + #endregion + private class SubToolStripRenderer : ToolStripRenderer { }