Treeview Filter and childnodes

7 posts, 1 answers
  1. willi
    willi avatar
    22 posts
    Member since:
    Oct 2006

    Posted 06 Apr Link to this post

    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

     

     

  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 06 Apr Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. willi
    willi avatar
    22 posts
    Member since:
    Oct 2006

    Posted 06 Apr in reply to Dimitar Link to this post

    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

  5. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 07 Apr Link to this post

    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.
  6. willi
    willi avatar
    22 posts
    Member since:
    Oct 2006

    Posted 07 Apr in reply to Dimitar Link to this post

    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 

  7. Answer
    Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 08 Apr Link to this post

    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.
  8. willi
    willi avatar
    22 posts
    Member since:
    Oct 2006

    Posted 12 Apr in reply to Hristo Link to this post

    Thank you very much, Thats it! It works!
Back to Top
UI for WinForms is Visual Studio 2017 Ready