This is a migrated thread and some comments may be shown as answers.

Treeview Filter and childnodes

6 Answers 364 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
willi
Top achievements
Rank 1
willi asked on 06 Apr 2016, 07:34 AM

Hi!

I'm trying to filter in a Treeview. The filter is working, but I need to show all the childs from the result-nodes.

I know there is custom filtering, but I have no clue how to do this.

Thanks in advance

Willi

 

 

6 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 06 Apr 2016, 09:57 AM
Hi Willi,

Thank you for writing.

This should be done by using custom filtering. To use the custom filtering you need to create a method. This method will be called for each node, in your case you need to check if the current node (passed as a parameter) mach your criteria, you should check if the node parent matches the criteria as well, and if it does, leave the node visible (return true). Detailed information is available here: Custom Filtering.

Let me know if you have additional questions.

Regards,
Dimitar
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
willi
Top achievements
Rank 1
answered on 06 Apr 2016, 01:35 PM

Hi!

Thanks for your answer. But as I mentioned - I had no clue how it should work in the custom filtering.

 

I tried this:

Private Sub popQualifikationAuswahl_Load(sender As Object, e As EventArgs) Handles Me.Load
       Dim sqlDef As SqlCommand = initSqlDef()
       sqlDef.CommandText = "select bezeichnung, parentId, Id, sapId from sapQualifikationen where deletedWhen is null"
       Dim dt As DataTable = getTable(sqlDef)
 
       With treeQualifikation
           .DisplayMember = "bezeichnung"
           .ParentMember = "parentId"
           .ChildMember = "Id"
           .DataSource = dt
           .ValueMember = "sapId"
           .SortOrder = Windows.Forms.SortOrder.Ascending
           .TreeViewElement.FilterPredicate = AddressOf FilterNode
       End With
   End Sub

 

Private Function FilterNode(node As RadTreeNode) As Boolean
    Console.WriteLine(node.Text)
    If node.Text.ToLower().Contains(node.TreeViewElement.Filter.ToString().ToLower()) Then
        Return True
    Else
        If node.Parent IsNot Nothing Then
            Return FilterNode(node.Parent)
        End If
    End If
 
    Return False
End Function

console.writeline only writes the names from the top-nodes...

 

Thanks

willi

0
Dimitar
Telerik team
answered on 07 Apr 2016, 10:08 AM
Hi Willi,

Thank you for writing back.

You are suing self-reference hierarchy and the method is not called for the entire hierarchy when the filter is changed, only for the currently visible nodes. If you expand the nodes you will notice that the method will be executed for the child levels as well.

Let me know if you have additional questions. 

Regards,
Dimitar
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
willi
Top achievements
Rank 1
answered on 07 Apr 2016, 11:42 AM

Hi!

Thanks, but it would be nice to provide a sample code, because even when I Expand all nodes before find (whitch takes a long time) just the root nodes are searched.Also tried to expand the node in the filterpredicate whitch does not work.

Regards,

willi 

0
Accepted
Hristo
Telerik team
answered on 08 Apr 2016, 02:05 PM
Hi Willi,

Thank you for writing back.

Please check the attached project suggesting a sample implementation. Basically, you would need iterate all nodes of your tree and mark those which should not be filtered out. The tricky part in this scenario is to cover all the paths in your tree containing the node against which you will validate.

Besides the project, I am also sending you a short video showing the result on my end.

I hope this helps. Please let me know if you need further assistance.

Regards,
Hristo Merdjanov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
willi
Top achievements
Rank 1
answered on 12 Apr 2016, 07:07 AM
Thank you very much, Thats it! It works!
Tags
Treeview
Asked by
willi
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
willi
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or