Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ private enum Flags : ushort
/// </summary>
ButtonLaunchedEditor = 0x0100,
NoDefault = 0x0200,
ResizableDropDown = 0x0400
ResizableDropDown = 0x0400,
EditMouseDown = 0x0800
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
PInvoke.SendMessage(EditTextBox, PInvoke.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);
PInvoke.SendMessage(EditTextBox, PInvoke.WM_LBUTTONUP, (WPARAM)0, (LPARAM)e.Location);
EditTextBox.SelectAll();
}

_rowSelectPos = Point.Empty;

_rowSelectTime = 0;
}
}
finally
{
EditMouseDown = false;
}
}

Expand Down Expand Up @@ -3998,7 +4013,7 @@ private void Refresh(bool fullRefresh, int startRow, int endRow)
startRow = 0;
}

if (OwnerGrid.HavePropertyEntriesChanged())
if (fullRefresh || OwnerGrid.HavePropertyEntriesChanged())
{
if (HasEntries && !InPropertySet && !CommitEditTextBox())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4122,6 +4122,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
{
}
Expand Down