From 7e50fda55fea24176c09d4386c1364b443b82279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9F=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BF=D0=BE=D0=B2?= Date: Tue, 19 Nov 2024 23:44:02 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D1=83=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B0=20=D0=B2=20TreeView,=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BF=D0=BE=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=BC=D0=BE=D0=B3=D1=83=D1=82=20=D0=B1=D1=8B=D1=82=D1=8C=20?= =?UTF-8?q?=D0=BB=D1=8E=D0=B1=D0=BE=D0=B3=D0=BE=20=D1=82=D0=B8=D0=BF=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormSolution/Components/UserControlTreeView.cs | 9 +++++---- WinFormSolution/WinFormsApp/Employee.cs | 4 +++- WinFormSolution/WinFormsApp/FormVisual.cs | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/WinFormSolution/Components/UserControlTreeView.cs b/WinFormSolution/Components/UserControlTreeView.cs index 2b94e06..007efc7 100644 --- a/WinFormSolution/Components/UserControlTreeView.cs +++ b/WinFormSolution/Components/UserControlTreeView.cs @@ -49,7 +49,7 @@ namespace Components int propIndex = GetNodeDepth(node); while (node != null) { - string propValue = node.Text; + object propValue = node.Tag; string propName = Hierarchy[propIndex].PropertyName; var prop = obj.GetType().GetProperty(propName); @@ -100,7 +100,7 @@ namespace Components { throw new PropertyNotDeclaratedException(hierarchyProperty.PropertyName); } - string? objectPropertyValue = objectPropertyInfo.GetValue(obj)?.ToString() ?? null; + object? objectPropertyValue = objectPropertyInfo.GetValue(obj); if (objectPropertyValue == null) { throw new PropertyNullException(hierarchyProperty.PropertyName); @@ -112,7 +112,7 @@ namespace Components { foreach (TreeNode childNode in nodes) { - if (childNode.Text == objectPropertyValue) + if (childNode.Text == objectPropertyValue.ToString()) { node = childNode; break; @@ -122,7 +122,8 @@ namespace Components if (node == null) { - node = nodes.Add(objectPropertyValue); + node = nodes.Add(objectPropertyValue.ToString()); + node.Tag = objectPropertyValue; } nodes = node.Nodes; diff --git a/WinFormSolution/WinFormsApp/Employee.cs b/WinFormSolution/WinFormsApp/Employee.cs index b6c215f..3c6790e 100644 --- a/WinFormSolution/WinFormsApp/Employee.cs +++ b/WinFormSolution/WinFormsApp/Employee.cs @@ -2,6 +2,7 @@ { public class Employee { + public int Id { get; set; } public string Departament { get; set; } public string Position { get; set; } public string Name { get; set; } @@ -9,6 +10,7 @@ public Employee() { } public Employee(string departament, string position, string surname, string name) { + Id = new Random().Next(4); Departament = departament; Position = position; Name = name; @@ -16,7 +18,7 @@ } public override string ToString() { - return Departament + ", " + Position + ", " + Surname + " " + Name; + return Id.ToString() + ", " + Departament + ", " + Position + ", " + Surname + " " + Name; } } } diff --git a/WinFormSolution/WinFormsApp/FormVisual.cs b/WinFormSolution/WinFormsApp/FormVisual.cs index 0221b34..85ec9f6 100644 --- a/WinFormSolution/WinFormsApp/FormVisual.cs +++ b/WinFormSolution/WinFormsApp/FormVisual.cs @@ -47,6 +47,7 @@ namespace WinFormsApp List<(string PropertyName, bool AlwaysCreateBranch)> hierarchy = [ + ("Id", false), ("Departament", false), ("Position", false), ("Surname", false),