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 @@ -316,7 +316,7 @@ private int AddInternal(TreeNode node, int delta)
}
}

if (tv is not null && tv.Sorted)
if (tv is not null && tv.Sorted && _owner.Nodes.FixedIndex == -1)
{
return _owner.AddSorted(tv, node);
}
Expand Down Expand Up @@ -344,7 +344,7 @@ private int AddInternal(TreeNode node, int delta)
tv.SelectedNode = node; // communicate this to the handle
}

if (tv is not null && tv.TreeViewNodeSorter is not null)
if (tv is not null && tv.TreeViewNodeSorter is not null && _owner.Nodes.FixedIndex == -1)
{
tv.Sort();
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/integration/WinformsControlsTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// Set STAThread
Thread.CurrentThread.SetApartmentState(ApartmentState.Unknown);
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);

AppContext.SetSwitch(TreeViewSortAddRangeTest.SwitchName, false);

ApplicationConfiguration.Initialize();

Application.SetColorMode(SystemColorMode.Classic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ private void ShowScenario(bool useAddRange)
_treeView.EndUpdate();

string method = useAddRange ? "AddRange(nodes)" : "Add(node) in a loop";
string order = string.Join(", ", _treeView.Nodes.Cast<TreeNode>().Select(n => n.Text));
string input = string.Join(", ", nodes.Select(n => n.Text));
string output = JoinNodeText(_treeView.Nodes.Cast<TreeNode>());
string input = JoinNodeText(nodes);

StringBuilder sb = new();
sb.AppendLine(DescribeEffectiveSwitch());
sb.AppendLine();
sb.AppendLine($"Insert method : {method}");
sb.AppendLine($"Input order : {input}");
sb.AppendLine($"Result order : {order}");
sb.AppendLine($"Reversed? : {(order == input ? "no (stable)" : "YES - equal nodes reversed")}");
sb.AppendLine($"Input: {input}");
sb.AppendLine($"Output: {output}");
sb.AppendLine($"Reversed? : {(output == input ? "no (stable)" : "YES - equal nodes reversed")}");
_output.Text = sb.ToString();
}

Expand All @@ -143,9 +143,8 @@ private void CompareSwitchInChildProcesses()
sb.AppendLine("Each line below is produced by a SEPARATE child process of this exact build,");
sb.AppendLine("so the AppContext switch is applied cleanly before the first AddRange call.");
sb.AppendLine();
sb.AppendLine(RunChild(self, ReportArg));
sb.AppendLine(RunChild(self, $"{ReportArg} --switch:true"));
sb.AppendLine(RunChild(self, $"{ReportArg} --switch:false"));
sb.AppendLine(RunChild(self, $"{ReportArg} --switch:true"));
_output.Text = sb.ToString();
}

Expand Down Expand Up @@ -224,13 +223,21 @@ internal static bool TryRunConsoleReport(string[] args, out int exitCode)
treeView.CreateControl();
treeView.Nodes.AddRange(nodes);

string order = string.Join(", ", treeView.Nodes.Cast<TreeNode>().Select(n => n.Text));
string input = string.Join(", ", nodes.Select(n => n.Text));
string state = AppContext.TryGetSwitch(SwitchName, out bool v) ? v.ToString() : "<default:true>";
Console.Out.WriteLine($"switch={state,-12} input=[{input}] result=[{order}] reversed={(order != input)}");
string output = JoinNodeText(treeView.Nodes.Cast<TreeNode>());
string input = JoinNodeText(nodes);
string state = AppContext.TryGetSwitch(SwitchName, out bool v)
? (v ? "ON" : "OFF")
: "<default:true>";

Console.Out.WriteLine($"switch {state} ->");
Console.Out.WriteLine($"Input: {input}");
Console.Out.WriteLine($"Output: {output}");
Console.Out.WriteLine($"Reversed: {output != input}");
return true;
}

private static string JoinNodeText(IEnumerable<TreeNode> nodes) => string.Join(",", nodes.Select(n => n.Text));

// A sorter that treats every node as equal, like several identically described items.
private sealed class AlwaysEqualComparer : IComparer
{
Expand Down