K. Sopheak K. Sopheak - 2 months ago 18
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.

Item1
|_____SubItem1
|___A
|___B


The result should be
Count:2
, Item:
A, B

Answer

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())
              })