# Find a RadTreeNode by the Value

## Environment

 Product Version 2018.3 911 Product RadTreeView for WinForms

## Description

RadTreeView supports searching for nodes by the Text of the node:

``````radTreeView1.Find("Test");
``````
``````radTreeView1.Find("Test")
``````

It is also possible to search by a Predicate which returns an array of all nodes that match the search criteria. A common case is to look for nodes by a certain value. The following approach gives you an easy way to search the nodes by the Value property.

Search nodes by Value

## Solution

In order to find the node by a given value, it is necessary to iterate all nodes recursively and check whether their Value property matches the search pattern:

``````  public RadForm1()
{
InitializeComponent();

int cnt = 0;
for (int i = 0; i < 5; i++)
{
cnt++;
node.Text = "Node" + cnt;
node.Value = cnt;
for (int j = 0; j < 5; j++)
{
cnt++;
childNode.Text = "ChildNode" + cnt;
childNode.Value = cnt;
for (int k = 0; k < 3; k++)
{
cnt++;
grandChildNode.Text = "ChildNode" + cnt;
grandChildNode.Value = cnt;
}
}
}

object value = 12;

if (foundNode != null)
{
}
}

{
{
if (node.Value.Equals(value))
{
return node;
}
else
{
if (n != null)
{
return n;
}
}
}

return null;
}

``````
``````     Public Sub New()
InitializeComponent()
Dim cnt As Integer = 0

For i As Integer = 0 To 5 - 1
cnt += 1
node.Text = "Node" & cnt
node.Value = cnt

For j As Integer = 0 To 5 - 1
cnt += 1
childNode.Text = "ChildNode" & cnt
childNode.Value = cnt

For k As Integer = 0 To 3 - 1
cnt += 1
grandChildNode.Text = "ChildNode" & cnt
grandChildNode.Value = cnt
Next
Next
Next

Dim value As Object = 12

If foundNode IsNot Nothing Then
End If

End Sub

Private Function FindNodeByValue(ByVal value As Object, ByVal nodes As Telerik.WinControls.UI.RadTreeNodeCollection) As RadTreeNode
For Each node As RadTreeNode In nodes

If node.Value.Equals(value) Then
Return node
Else
Dim n As RadTreeNode = FindNodeByValue(value, node.Nodes)

If n IsNot Nothing Then
Return n
End If
End If
Next

Return Nothing
End Function

``````