Skip to content

Commit c7c7953

Browse files
Epica3055Tanya-Solyanik
authored andcommitted
fix issue 11243 TreeNodeCollection.AddRange has been broken in .NET 8 and no longer results in TreeNodes being drawn at the correct location
1 parent 3365859 commit c7c7953

File tree

7 files changed

+224
-94
lines changed

7 files changed

+224
-94
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Collections;
5+
6+
namespace System.Windows.Forms;
7+
8+
internal class ArraySubsetEnumerator : IEnumerator
9+
{
10+
private readonly object[] _array;
11+
private readonly int _total;
12+
private int _current;
13+
14+
public ArraySubsetEnumerator(object[] array, int count)
15+
{
16+
Debug.Assert(count == 0 || array is not null, "if array is null, count should be 0");
17+
Debug.Assert(array is null || count <= array.Length, "Trying to enumerate more than the array contains");
18+
_array = array!;
19+
_total = count;
20+
_current = -1;
21+
}
22+
23+
public bool MoveNext()
24+
{
25+
if (_current < _total - 1)
26+
{
27+
_current++;
28+
return true;
29+
}
30+
31+
return false;
32+
}
33+
34+
public void Reset() => _current = -1;
35+
36+
public object? Current => _current == -1 ? null : _array[_current];
37+
}

src/System.Windows.Forms/src/System/Windows/Forms/TreeNode.TreeNodeAccessibleObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ internal override void SelectItem()
120120
internal override bool IsPatternSupported(UiaCore.UIA patternId)
121121
=> patternId switch
122122
{
123-
UiaCore.UIA.ExpandCollapsePatternId => _owningTreeNode.childNodes.Count > 0,
123+
UiaCore.UIA.ExpandCollapsePatternId => _owningTreeNode.childCount > 0,
124124
UiaCore.UIA.LegacyIAccessiblePatternId => true,
125125
UiaCore.UIA.ScrollItemPatternId => true,
126126
UiaCore.UIA.SelectionItemPatternId => true,

0 commit comments

Comments
 (0)