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

Self Referencing Treeview loses children in RadDock

1 Answer 122 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 14 Oct 2012, 04:09 AM
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.BeginUpdate()
    Filter_Equipment.DataSource = Nothing
    Filter_Equipment.Nodes.Clear()
    'Filter_Equipment.Nodes.Refresh()
 
    LoadEquipmentTreeView()
    Filter_Equipment.EndUpdate()
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"))
    Filter_Equipment.Nodes.Refresh()
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....

1 Answer, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 17 Oct 2012, 12:53 PM
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()
            InitializeComponent()
 
            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
            window.Controls.Add(treeView)
            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
            treeView.ExpandAll()
        End Sub
 
        Private Sub radDock_DockStateChanged(sender As Object, e As DockWindowEventArgs)
            Dim nodesStack As New Stack(Of RadTreeNodeCollection)()
            nodesStack.Push(treeView.Nodes)
 
            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
                        nodesStack.Push(nodes(i).Nodes)
                    End If
                Next
            End While
 
            checkedNodes.Clear()
        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
                checkedNodes.Add(id)
            Else
                checkedNodes.Remove(id)
            End If
        End Sub
    End Class
End Namespace

I hope this helps.

Regards,
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.
Tags
Treeview
Asked by
Robert
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Share this question
or