Self Referencing Treeview loses children in RadDock

2 posts, 0 answers
  1. Robert
    Robert avatar
    7 posts
    Member since:
    Jun 2012

    Posted 13 Oct 2012 Link to this post

    Hello all

    I've got a strange one. I've got a treeview with check boxes in a tool window in a RadDock.

    When I change the docking on the window, the treeview loses its children. The parents stay, but the children are gone - there are no children at all and the parent node doesn't expand.

    As a work around I tried reloading the treeview after the dock state changes, but then the children get reloaded, so that every time I dock I get a new set of children nested inside the existing children. I've tried clearing the treeview and setting the data source to nothing before reloading. Here's the code:

    Private Sub DockMain_DockStateChanged(sender As System.Object, e As Telerik.WinControls.UI.Docking.DockWindowEventArgs) Handles DockMain.DockStateChanged
        Filter_Equipment.DataSource = Nothing
    End Sub

    Private Sub LoadEquipmentTreeView()
        Filter_Equipment.DataSource = _Context.FindEquipmentType(Nothing, Nothing, Nothing)
        Filter_Equipment.DisplayMember = "EquipmentTypeName"
        Filter_Equipment.ValueMember = "EquipmentTypeID"
        Filter_Equipment.RelationBindings.Add(New RelationBinding(_Context.FindEquipment(Nothing, Nothing, Nothing, Nothing, Nothing, Nothing), "EquipmentShortName", "EquipmentTypeID", "EquipmentTypeID", "EquipmentID"))
    End Sub

    Some screenshots attached - I have blocked out the values displayed in the nodes because it's client data, but hopefully you can see.

    Any suggestions?

    Thanks in advance....
  2. Julian Benkov
    Julian Benkov avatar
    1135 posts

    Posted 17 Oct 2012 Link to this post

    Hi Robert,

    The issue is related to the rebind operation after the Parent of RadTreeView is changed during the dock operation. The process in this situation is absolutely valid. We will continue researching how to suspend/resume the binding in this case to save the state of RadTreeView control without changing the functionality in the general case. Currently, you can save and restore the Checkbox state of the RadTreeView control using a HashSet collection. Here is an example:

    Imports System.Collections.Generic
    Imports System.Data
    Imports System.Windows.Forms
    Imports Telerik.WinControls.UI
    Imports Telerik.WinControls.UI.Docking
    Namespace Lab.Tree
        Public Partial Class TreeToolWindowBindForm
            Inherits Form
            Private radDock As New RadDock()
            Private treeView As New RadTreeView()
            Private checkedNodes As New HashSet(Of Integer)()
            Public Sub New()
                radDock.Dock = DockStyle.Fill
                radDock.Parent = Me
                radDock.DockStateChanged += radDock_DockStateChanged
                Dim window As New ToolWindow()
                treeView.Dock = DockStyle.Fill
                treeView.CheckBoxes = True
                treeView.NodeCheckedChanged += treeView_NodeCheckedChanged
                radDock.DockWindow(window, DockPosition.Left)
                Dim table As New DataTable()
                table.Columns.Add("Id", GetType(Integer))
                table.Columns.Add("ParentId", GetType(Integer))
                table.Columns.Add("Name", GetType(String))
                table.Columns.Add("Valid", GetType(Boolean))
                table.Rows.Add(1, 0, "Node1", True)
                table.Rows.Add(2, 0, "Node2", False)
                table.Rows.Add(3, 1, "Node3", True)
                table.Rows.Add(4, 1, "Node4", True)
                table.Rows.Add(5, 0, "Node5", True)
                table.Rows.Add(6, 5, "Node6", False)
                table.Rows.Add(7, 3, "Node7", True)
                table.Rows.Add(8, 3, "Node8", True)
                table.Rows.Add(9, 2, "Node9", False)
                table.Rows.Add(10, 0, "Node10", True)
                treeView.ChildMember = "Id"
                treeView.ParentMember = "ParentId"
                treeView.ValueMember = "Valid"
                treeView.DisplayMember = "Name"
                treeView.DataSource = table
            End Sub
            Private Sub radDock_DockStateChanged(sender As Object, e As DockWindowEventArgs)
                Dim nodesStack As New Stack(Of RadTreeNodeCollection)()
                While nodesStack.Count > 0
                    Dim nodes As RadTreeNodeCollection = nodesStack.Pop()
                    For i As Integer = 0 To nodes.Count - 1
                        Dim id As Integer = CInt(TryCast(nodes(i).DataBoundItem, DataRowView)("Id"))
                        nodes(i).Checked = checkedNodes.Contains(id)
                        If nodes(i).Nodes.Count > 0 Then
                        End If
                End While
            End Sub
            Private Sub treeView_NodeCheckedChanged(sender As Object, e As RadTreeViewEventArgs)
                Dim id As Integer = CInt(TryCast(e.Node.DataBoundItem, DataRowView)("Id"))
                If e.Node.Checked Then
                End If
            End Sub
        End Class
    End Namespace

    I hope this helps.

    Julian Benkov
    the Telerik team
    You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
  3. DevCraft R3 2016 release webinar banner
Back to Top