diff --git a/ICSharpCode.ILSpyX/TreeView/SharpTreeNodeCollection.cs b/ICSharpCode.ILSpyX/TreeView/SharpTreeNodeCollection.cs index 8b69a9553d..d724285763 100644 --- a/ICSharpCode.ILSpyX/TreeView/SharpTreeNodeCollection.cs +++ b/ICSharpCode.ILSpyX/TreeView/SharpTreeNodeCollection.cs @@ -73,7 +73,10 @@ void ThrowIfValueIsNullOrHasParent(SharpTreeNode node) public SharpTreeNode this[int index] { get { - return list[index]; + if (index >= 0 && index < list.Count) + return list[index]; + else + return null; } set { ThrowOnReentrancy(); diff --git a/ILSpy/Controls/TreeView/SharpTreeView.cs b/ILSpy/Controls/TreeView/SharpTreeView.cs index faa7cb2f05..ab86539bd9 100644 --- a/ILSpy/Controls/TreeView/SharpTreeView.cs +++ b/ILSpy/Controls/TreeView/SharpTreeView.cs @@ -561,8 +561,12 @@ List BuildDropTargets(SharpTreeViewItem item, DragEventArgs e) { if (node.IsExpanded && node.Children.Count > 0) { - var firstChildItem = ItemContainerGenerator.ContainerFromItem(node.Children[0]) as SharpTreeViewItem; - TryAddDropTarget(result, firstChildItem, DropPlace.Before, e); + var nodeChild = node.Children[0]; + if (nodeChild != null) + { + var firstChildItem = ItemContainerGenerator.ContainerFromItem(node.Children[0]) as SharpTreeViewItem; + TryAddDropTarget(result, firstChildItem, DropPlace.Before, e); + } } else {