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),