FindNode.... not found...

Hi folks,

I am messing around with treeviews and listviews, and I am missing something.

In the documentation I encounter commands like FindNode, TreeNodeConverter, ConvertFromString etc. But I cannot get it to work. In the sample provided by MS (below) it results in the errors like "FindNode is not a member of "System.Windows.Forms.TreeView".

Also the parameters like ValuePath are not found (not member of treeNode). I tried to import the namespace mentioned, but it is not "there".

Have I stumbled on a difference between VBA and VS2005, or is it just "not ready yet". Searching the internet yields no proper samples... ..

I intend to use the Tree- and ListView controls a lot in the project I am currently working on, and proper understanding of the matter is essential. Even Petroutsos book does not help me out.

Any leads

Thymen

Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)

' Find the node specified by the user.

Dim node As TreeNode = TreeView.FindNode(Server.HtmlEncode(ValuePathText.Text))

If Not node Is Nothing Then

' Indicate that the node was found.

Message.Text = "The specified node (" & node.ValuePath & ") was found."

Else

' Indicate that the node is not in the TreeView control.

Message.Text = "The specified node (" & ValuePathText.Text & ") is not in this TreeView control."

End If

End Sub



Answer this question

FindNode.... not found...

  • osamaT

     

    Hi Thymen... I'm afraid I have a little bit of bad news for. You made a mistake that is easy to make:

    System.Web.UI.WebControls.TreeNode.ValuePath() As String

    Web.UI means it's for ASP not Windows.Forms. When you are looking up controls, unless you are programming for the web, you cant use this class. that's what this doesn't work and why you can't find it. Have you been introduced to the Object Browser yet It's icon with the pink in it (my favorite!!!). Open up the object browser and browse through it. Before you're done enter:   ValuePath path into the window and see what you see.

    Also if you enter Find... eventually you'll see this:

    System.Windows.Forms.TreeNodeCollection.Find(String, Boolean) As System.Windows.Forms.TreeNode()

     



  • Michael C. Neel

    there's a really good example at recursing through nodes in help. It's much shorter than that.

    This is roughly the example from Help.

    ' Call the procedure using the top nodes of the treeview.
    Private Sub CallRecursive(ByVal aTreeView As TreeView)
      Dim n As TreeNode
      For Each n In aTreeView.Nodes
       PrintRecursive(n)
      Next
    End Sub
    Private Sub PrintRecursive(ByVal n As TreeNode)
      System.Diagnostics.Debug.WriteLine(n.Text)
      MessageBox.Show(n.Text)
      Dim aNode As TreeNode
      For Each aNode In n.Nodes
       PrintRecursive(aNode)
      Next
    End Sub
    
    


  • djshades2004

    ReneeC,

    thanks.... something new every day..

    I whipped up something myself.. but I'll try your stuff too.

    Private Function fnFindNodeRecursive(ByVal n As TreeNode, ByVal aPath As String) As TreeNode

    fnFindNodeRecursive = Nothing

    For Each node As TreeNode In n.Nodes

    If node.FullPath = aPath Then

    fnFindNodeRecursive = node

    Exit Function

    End If

    fnFindNodeRecursive = fnFindNodeRecursive(node, aPath)

    If fnFindNodeRecursive IsNot Nothing Then Exit Function

    Next

    End Function

    Private Function fnFindNode(ByVal aTreeView As TreeView, ByVal aPath As String) As TreeNode

    fnFindNode = Nothing

    For Each node As TreeNode In aTreeView.Nodes

    If node.FullPath = aPath Then

    fnFindNode = node

    Exit Function

    End If

    fnFindNode = fnFindNodeRecursive(node, aPath)

    If fnFindNode IsNot Nothing Then Exit Function

    Next node

    End Function


  • FindNode.... not found...