Current location - Loan Platform Complete Network - Big data management - How to get the number of sibling nodes in TreeView in C#?
How to get the number of sibling nodes in TreeView in C#?
Hello, here is a code to find the siblings of a node (including itself) by looping through the siblings:

int nodeCount = 1;

TreeNode selectedNode = this.treeView1.SelectedNode;

TreeNode nextNode = selectedNode.NextNode;

TreeNode previousNode = selectedNode.PrevNode;

while (nextNode ! = null)

{

nodeCount++;

nextNode = nextNode.NextNode;

}

while (previousNode ! = null)

{

nodeCount++;

previousNode = previousNode.PrevNode;

}