How can I determine the node level of a node in my treeview

Platform: WinForms| Category: TreeView

Here is a code snippet suggested by Mattias Sjögren on the microsoft.public.dotnet.languages.csharp newsgroup.

[C#]
	public int NodeLevel(TreeNode node)
	{
		int level = 0;
		while ((node = node.Parent) != null) level++;
		return level;
	}
[VB.NET]
	Public Sub NodateLevel(ByVal node as TreeNode) As Integer
		Dim level as Integer = 0
		While Not node Is Nothing
			node = node.Parent
			level = level + 1
		End While
	End Sub

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.