Skip to content
Open
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 @@ -3710,15 +3710,10 @@ private void SelectViewTabButton(ToolStripButton button, bool updateSelection)

private bool SelectViewTabButtonDefault(ToolStripButton? button)
{
if (button is null)
{
return false;
}

// Is this tab button checked? If so, do nothing.
if (button == _selectedTab?.Button)
{
button.Checked = true;
button?.Checked = true;
return true;
}

Expand Down Expand Up @@ -3755,7 +3750,6 @@ private bool SelectViewTabButtonDefault(ToolStripButton? button)

// Select the first tab if we didn't find that one.
_selectedTab = _tabs[PropertiesTabIndex];
Debug.Assert(_tabs[PropertiesTabIndex].Tab.GetType() == DefaultTabType, "First item is not property tab!");
SelectViewTabButton(_tabs[PropertiesTabIndex].Button, updateSelection: false);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2360,6 +2360,20 @@ public void PropertyGrid_PropertySort_SetWithHandle_GetReturnsExpected(PropertyS
Assert.Equal(0, createdCallCount);
}

[WinFormsFact]
public void PropertyGrid_SelectedObject_SetAfterReplacingDefaultTab_UsesCustomTab()
{
using PropertyGrid control = new();
control.PropertyTabs.RemoveTabType(typeof(PropertiesTab));
control.PropertyTabs.AddTabType(typeof(ReplacementPropertyTab), PropertyTabScope.Static);

using Button selectedObject = new();
control.SelectedObject = selectedObject;

Assert.Equal(selectedObject, control.SelectedObject);
Assert.IsType<ReplacementPropertyTab>(control.SelectedTab);
}

[WinFormsFact]
public void PropertyGrid_PropertyTabCollection_AddAndRemoveTabType_Success()
{
Expand All @@ -2382,6 +2396,27 @@ private class TestPropertyTab : PropertyTab
public override PropertyDescriptorCollection GetProperties(object component, Attribute[] attributes) => throw new NotImplementedException();
}

private class ReplacementPropertyTab : PropertyTab, IDisposable
{
private Bitmap _bitmap;

public override string TabName => "ReplacementPropertyTab";

public override Bitmap Bitmap => _bitmap ??= new(10, 10);

public override PropertyDescriptorCollection GetProperties(object component, Attribute[] attributes)
=> TypeDescriptor.GetProperties(component, attributes);

public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attributes)
=> TypeDescriptor.GetProperties(component, attributes);

public override void Dispose()
{
_bitmap?.Dispose();
base.Dispose();
}
}

[WinFormsFact]
public void PropertyGrid_SelectedGridItem_SetNull_ThrowsArgumentNullException()
{
Expand Down