Skip to content

Add new child nodes to selected node via SelectionChanged event #3517

Answered by tznind
dasien asked this question in Q&A
Discussion options

You must be logged in to vote

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 of TreeNode but you could do a similar thing with TreeNode class if you like. I can provide example if needed.

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);
}
f…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by dasien
Comment options

You must be logged in to vote
5 replies
@tznind
Comment options

@dasien
Comment options

@dasien
Comment options

@tznind
Comment options

@dasien
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants