Library code snippets
Some usefull TreeNode and TreeView functions
By Matej Kasper, published on 03 Jun 2006
Page 1 of 5
- Obtaining true if tree/node/view has some selected node
- Querying checked nodes, signed by some tag.
- Comparing two treeNodes
- Assigning Image to nodes according to .Tag
- Some required 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
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
Related articles
Related discussion
-
Sharepoint : GroupBy results according to custom property
by sampadasanjay (0 replies)
-
i have struck with my project in vb.net
by jetski (4 replies)
-
Error in VB code
by glib162002 (0 replies)
-
Very slow inserts using SqlCommand.ExecuteNonQuery()
by porchelvi (1 replies)
-
Datagridview Setting datasource property of datagridviewcomboboxcell at run time
by sairfan1 (2 replies)
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum)
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!
This thread is for discussions of Some usefull TreeNode and TreeView functions.