K. Sopheak K. Sopheak - 28 days ago 9x
Vb.net Question

How to count and get child items of the last level of tree view node in vb net?

I want to count and get child name of treeview if there is only on root element like the following picture. I am in Item1 position.


The result should be
, Item:
A, B


Also a possible solution, using LINQ:

Dim result = (From node as TreeNode in TreeView1.TopNode.Nodes
              Select New With {
                .Count = node.Nodes.Count,
                .Items = String.Join(",", node.Nodes.Cast(Of TreeNode).AsEnumerable().Select(Function(childNode) childNode.Name).ToArray())