This content is not currently approved and is visible here for review only.

Library code snippets

Some usefull TreeNode and TreeView functions

Obtaining true if tree/node/view has some selected node

Sure, It is bit recursive, but not falling to now...
I needed that when using treenode click event and wanting to show some
contextMenu with info about selected node - because I didn't find any other built in
way to get info, if some node is selected...
That with node as argument are needed only by that with treeview,
I didn't use them stand alone...


  ''' <summary>Returns true if some node in TreeView tw is selected.</summary>
   Function HasSelectedNode (ByVal tw As TreeView ) As Boolean
     Dim i As Integer
     With tw .Nodes
       For i = 0 To . Count - 1
         If tw .Nodes . Item (i ).IsSelected Then Return True
         If HasSelectedNode (tw .Nodes . Item (i )) Then Return True
       Next
     End With
     Return False
   End Function
   ''' <summary>Returns true if some node in TreeView root node is selected.</summary>
   Function HasSelectedNode (ByVal node As TreeNode )
     Dim i As Integer
     With node .Nodes
       For i = 0 To . Count - 1
         If . Item (i ).IsSelected Then Return True
         If HasSelectedNode (. Item (i )) Then Return True
       Next
     End With
     Return False
   End Function
   ''' <summary>Returns true if some node in TreeView tw is checked.</summary>
   Function HasCheckedNode (ByVal tw As TreeView ) As Boolean
     Dim i As Integer
     With tw .Nodes
       For i = 0 To . Count - 1
         If . Item (i ).Checked Then Return True
         If HasCheckedNode (. Item (i )) Then Return True
       Next
     End With
     Return False
   End Function
   ''' <summary>Returns true if some node in TreeView root node is checked.</summary>
   Function HasCheckedNode (ByVal node As TreeNode )
     Dim i As Integer
     With node .Nodes
       For i = 0 To . Count - 1
         If . Item (i ).Checked Then Return True
         If HasCheckedNode (. Item (i )) Then Return True
       Next
     End With
     Return False
   End Function

Comments

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of Some usefull TreeNode and TreeView functions.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related jobs

Events coming up

  • Dec 6

    Developing AJAX Web Applications with Castle Monorail

    London, United Kingdom

    Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!