dotnet / dotnet/winforms

PropertyGrid randomly loses toolbar items

Open
#9,223 6 comments 1 reaction 1 assignee Claimed by @JeremyKuhne View on GitHub
:beetle: bug area-controls-PropertyGrid
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

### .NET version

Microsoft.WindowsDesktop.App 6.0.16

### Did it work in .NET Framework?

Yes

### Did it work in any of the earlier releases of .NET Core or .NET 5+?

No idea

### Issue description

I have an app with a `PropertyGrid` control, which is customised with few extra buttons.
![image](https://github.com/dotnet/winforms/assets/4403806/1fe7c3ce-55f4-486f-9934-dd0c3e03fea0)

I observed that the custom buttons randomly disappear. Here's the trace of the issue:
```
DarcUI.dll!DarcUI.ExtendedPropertyGrid.ToolStripButton2.OnParentChanged(System.Windows.Forms.ToolStrip oldParent = {System.Windows.Forms.PropertyGridToolStrip}, System.Windows.Forms.ToolStrip newParent = null) Line 29 C#
> System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.SetOwner(System.Windows.Forms.ToolStrip newOwner) Line 3910 C#
System.Windows.Forms.dll!System.Windows.Forms.ToolStripItemCollection.OnAfterRemove(System.Windows.Forms.ToolStripItem item = {DarcUI.ExtendedPropertyGrid.ToolStripButton2}) Line 443 C#
System.Windows.Forms.dll!System.Windows.Forms.ToolStripItemCollection.Clear() Line 225 C#
System.Windows.Forms.dll!System.Windows.Forms.PropertyGrid.SetupToolbar(bool fullRebuild) Line 4302 C#
System.Windows.Forms.dll!System.Windows.Forms.PropertyGrid.OnSystemColorsChanged(System.EventArgs e = {System.EventArgs}) Line 4508 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.OnSystemColorsChanged(System.EventArgs e = {System.EventArgs}) Line 11230 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.OnSystemColorsChanged(System.EventArgs e = {System.EventArgs}) Line 11230 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.OnSystemColorsChanged(System.EventArgs e = {System.EventArgs}) Line 11230 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.OnSystemColorsChanged(System.EventArgs e = {System.EventArgs}) Line 11230 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.UserPreferenceChanged(object sender, Microsoft.Win32.UserPreferenceChangedEventArgs pref) Line 13440 C#
```

The issue appears to be here:
https://github.com/dotnet/winforms/blob/89fcc580afb06911254f00cfc6650b0496c033ad/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGrid.cs#L3940-L3944

The `buttonList` is rebuilt from only pre-defined elements, completely ignoring any additional elements the toolstrip contained.

### Steps to reproduce

I can craft a sample, if necessary.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.