|
Hello, I am trying to dynamically add to the Any ideas would be greatly appreciated. Code below. |
Replies: 2 comments 5 replies
|
This use case is better supported by implementing the You can read more about ITreeView in Tree View Deep Dive docs
I have used using Terminal.Gui;
using Terminal.Gui.Trees;
Application.Init();
var w = new Window();
var tv = new TreeView<object>(new MyTreeBuilder());
tv.Width = Dim.Fill();
tv.Height = Dim.Fill();
tv.AddObjects(new[] {
new MyObject(),
new MyObject(),
new MyObject()
});
w.Add(tv);
try
{
Application.Run(w);
}
finally
{
Application.Shutdown();
}
internal class MyTreeBuilder : ITreeBuilder<object>
{
public bool SupportsCanExpand => true;
public bool CanExpand(object toExpand)
{
// Anything can be expanded
return true;
}
public IEnumerable<object> GetChildren(object forObject)
{
return new[] { new MyObject() };
}
}
class MyObject
{
Guid guid = Guid.NewGuid();
public override string ToString()
{
return guid.ToString();
}
} |
|
Thank you very much for the example, @tznind! I can convert it to a |

This use case is better supported by implementing the
ITreeBuilderinstead. Here is an example:You can read more about ITreeView in Tree View Deep Dive docs
ITreeBuilderis interrogated automatically when nodes become visible and/or are expanded.I have used
objectinstead ofTreeNodebut you could do a similar thing withTreeNodeclass if you like. I can provide example if needed.