Posted on: 6/2/2013 1:27:21 PM | Views : 539

I need to remove parent node that not have child node and it's not a link to form but while processing always show "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" what is the best way to solve this? Thanks
Private Sub checkEmptyNode(ByVal T As TreeView) For i As Integer = 0 To T.Nodes.Count - 1 If T.Nodes(i).ChildNodes.Count > 0 Then For j As Integer = 0 To T.Nodes(i).ChildNodes.Count - 1
If T.Nodes(i).ChildNodes(j).ChildNodes.Count > 0 Then RemoveEmptyNode(T.Nodes(i).ChildNodes(j).ChildNodes) Else If String.IsNullOrEmpty(T.Nodes(i).ChildNodes(j).NavigateUrl.Trim()) Then T.Nodes(i).ChildNodes(j).Parent.ChildNodes.Remove(T.Nodes(i).ChildNodes(j)) End If End If Next Else If String.IsNullOrEmpty(T.Nodes(i).NavigateUrl.Trim()) Then T.Nodes.Remove(T.Nodes(i)) End If End If Next End Sub

< ...

Go to the complete details ...