K. Sopheak K. Sopheak - 1 year ago 76
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

Answer Source

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())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download