Skip to content

Commit

Permalink
[release/8.0] Fix PropertyGrid.RemoveTabType method (#10589)
Browse files Browse the repository at this point in the history
* Fix RemoveTabType method

* Add unit test

---------

Co-authored-by: thomasnaletsg <155535130+thomasnaletsg@users.noreply.github.com>
Co-authored-by: Loni Tra <lonitra@microsoft.com>
  • Loading branch information
3 people authored Jan 5, 2024
1 parent 54dca45 commit 9014c03
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3580,7 +3580,7 @@ internal void RemoveTab(Type tabType)
int tabIndex = -1;
for (int i = 0; i < _tabs.Count; i++)
{
if (tabType == _tabs[i].GetType())
if (tabType == _tabs[i].Tab.GetType())
{
tabIndex = i;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Moq;
using Point = System.Drawing.Point;
using Size = System.Drawing.Size;
using System.Windows.Forms.Design;

namespace System.Windows.Forms.Tests;

Expand Down Expand Up @@ -2357,6 +2358,28 @@ public void PropertyGrid_PropertySort_SetWithHandle_GetReturnsExpected(PropertyS
Assert.Equal(0, createdCallCount);
}

[WinFormsFact]
public void PropertyGrid_PropertyTabCollection_AddAndRemoveTabType_Success()
{
using PropertyGrid grid = new();
Assert.Equal(1, grid.PropertyTabs.Count);

grid.PropertyTabs.AddTabType(typeof(TestPropertyTab));
Assert.Equal(2, grid.PropertyTabs.Count);

grid.PropertyTabs.RemoveTabType(typeof(TestPropertyTab));
Assert.Equal(1, grid.PropertyTabs.Count);
}

private class TestPropertyTab : PropertyTab
{
public override string TabName => "TestTabName";

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

public override PropertyDescriptorCollection GetProperties(object component, Attribute[] attributes) => throw new NotImplementedException();
}

[WinFormsFact]
public void PropertyGrid_SelectedGridItem_SetNull_ThrowsArgumentNullException()
{
Expand Down

0 comments on commit 9014c03

Please sign in to comment.