-
Hello, I am trying to dynamically add to the Any ideas would be greatly appreciated. Code below.
|
Beta Was this translation helpful? Give feedback.
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();
}
} |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the example, @tznind! I can convert it to a |
Beta Was this translation helpful? Give feedback.
This use case is better supported by implementing the
ITreeBuilder
instead. Here is an example:You can read more about ITreeView in Tree View Deep Dive docs
ITreeBuilder
is interrogated automatically when nodes become visible and/or are expanded.I have used
object
instead ofTreeNode
but you could do a similar thing withTreeNode
class if you like. I can provide example if needed.