From 96353d7682699ee3d52387ff551694d27f385a36 Mon Sep 17 00:00:00 2001 From: "nikbel2004@outlook.com" Date: Mon, 21 Oct 2024 02:38:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyCustomComponents/CustomTreeView.cs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Lab 1/Belianin_1/MyCustomComponents/CustomTreeView.cs b/Lab 1/Belianin_1/MyCustomComponents/CustomTreeView.cs index e670360..db22a62 100644 --- a/Lab 1/Belianin_1/MyCustomComponents/CustomTreeView.cs +++ b/Lab 1/Belianin_1/MyCustomComponents/CustomTreeView.cs @@ -121,15 +121,8 @@ namespace MyCustomComponents throw new ArgumentNullException("Added object is null"); } - // Ищем индекс свойства в иерархии - int index = hierarchy.IndexOf(propertyName); - if (index == -1) - { - throw new PropertyNullException("Property not found in hierarchy"); - } - - // Получаем первый узел в дереве, либо нулл, если узлов нет - TreeNode currentNode = treeView.SelectedNode; + // Получаем первый узел в дереве + TreeNode currentNode = null; // Проходимся по иерархии foreach (var property in hierarchy) @@ -140,13 +133,13 @@ namespace MyCustomComponents if (currentNode == null) { - currentNode = treeView.Nodes.Cast() - .FirstOrDefault(n => n.Text == value) ?? treeView.Nodes.Add(value); + currentNode = treeView.Nodes.Cast().FirstOrDefault(n => n.Text == value) + ?? treeView.Nodes.Add(value); } else { var childNode = currentNode.Nodes.Cast().FirstOrDefault(n => n.Text == value); - + // Проверка нужно ли нам создавать дочерний узел if (childNode == null || createNewBranch) {