2022-10-08 19:15:51 +03:00

63 lines
1.5 KiB
C#

using System.Collections.Generic;
using System.Linq;
namespace TelegramBotBase.Controls.Inline
{
public class TreeViewNode
{
public string Text { get; set; }
public string Value { get; set; }
public string Url { get; set; }
public List<TreeViewNode> ChildNodes { get; set; } = new List<TreeViewNode>();
public TreeViewNode ParentNode { get; set; }
public TreeViewNode(string text, string value)
{
this.Text = text;
this.Value = value;
}
public TreeViewNode(string text, string value, string url) : this(text, value)
{
this.Url = url;
}
public TreeViewNode(string text, string value, params TreeViewNode[] childnodes) : this(text, value)
{
foreach(var c in childnodes)
{
AddNode(c);
}
}
public void AddNode(TreeViewNode node)
{
node.ParentNode = this;
ChildNodes.Add(node);
}
public TreeViewNode FindNodeByValue(string value)
{
return ChildNodes.FirstOrDefault(a => a.Value == value);
}
public string GetPath()
{
var s = "\\" + Value;
var p = this;
while (p.ParentNode != null)
{
s = "\\" + p.ParentNode.Value + s;
p = p.ParentNode;
}
return s;
}
}
}