To reproduce: please run the attached sample project and follow the steps in the attached sample gif file.
Workaround: instead of filtering the nodes, you can manipulate the RadTreeNode.Visible property considering the filter criteria and whether the node contains a child that matches the filter.
public RadForm1()
{
InitializeComponent();
this.radTreeView1.ShowLines = true;
}
private void FilterNode(RadTreeNode node)
{
bool atLeastOneChildMatches = false;
ChildNodeContains(this.radTextBox1.Text.ToLower(), node.Nodes, ref atLeastOneChildMatches);
if (node.Text.ToLower().Contains(this.radTextBox1.Text.ToLower()) || atLeastOneChildMatches)
{
node.Visible = true;
}
else
{
node.Visible = false;
}
}
private void ChildNodeContains(string filterCritria, RadTreeNodeCollection nodes, ref bool atLeastOneChildMatches)
{
foreach (RadTreeNode node in nodes)
{
if (node.Text.ToLower().Contains(filterCritria))
{
atLeastOneChildMatches = true;
return;
}
if (atLeastOneChildMatches == false && node.Nodes.Count > 0)
{
ChildNodeContains(filterCritria, node.Nodes, ref atLeastOneChildMatches);
}
}
}
private void radTextBox1_TextChanged(object sender, EventArgs e)
{
PerformFilter(this.radTreeView1.Nodes);
}
private void PerformFilter(RadTreeNodeCollection nodes)
{
foreach (RadTreeNode node in nodes)
{
FilterNode(node);
if (node.Nodes.Count > 0)
{
PerformFilter(node.Nodes);
}
}
}