Load On Demand Scenario - collapse all child nodes when parent node is collapsed

1 posts, 0 answers
  1. Johnathan
    Johnathan avatar
    40 posts
    Member since:
    Sep 2012

    Posted 20 Feb 2018 Link to this post


    I'm using the Load On Demand Scenario & I'm attempting to force all child nodes to collapse when its parent has collapsed. Here is the code that I have so far. Any help on this would be greatly appreciated.

    Private Sub iTeam_DynamicOrgChart_Load(sender As Object, e As EventArgs) Handles Me.Load
            Dim oConn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("Connection").ConnectionString)
            Dim oCmd As New SqlCommand
            Dim oData As SqlDataReader
            Dim oAdapter As New SqlDataAdapter(oCmd)
            Dim oDataSet As New DataSet
                'get employee hierarchy
                With oCmd
                    .Connection = oConn
                    .CommandType = Data.CommandType.StoredProcedure
                    .CommandText = "EmployeeHierachySP"
                    .Parameters.AddWithValue("@NameOnly", NameOnly.Checked)
                End With
                With OrgChart
                    .DisableDefaultImage = True
                    .LoadOnDemand = OrgChartLoadOnDemand.Nodes
                    .EnableDrillDown = True
                    .PersistExpandCollapseState = True
                    .DataTextField = "UserName"
                    .DataFieldID = "UserID"
                    .DataFieldParentID = "ManagerUserID"
                    .DataCollapsedField = "Collapsed"
                    .DataSource = oDataSet
                    '.GroupColumnCount = 4
                    '.GroupEnabledBinding.GroupItemBindingSettings.DataTextField = "UserName"
                    '.GroupEnabledBinding.GroupItemBindingSettings.DataFieldID = "UserID"
                    '.GroupEnabledBinding.GroupItemBindingSettings.DataFieldNodeID = "ManagerUserID"
                    '.GroupEnabledBinding.GroupItemBindingSettings.DataSource = oDataSet
                    '.GroupEnabledBinding.NodeBindingSettings.DataFieldID = "UserID"
                    '.GroupEnabledBinding.NodeBindingSettings.DataFieldParentID = "ManagerUserID"
                    '.GroupEnabledBinding.NodeBindingSettings.DataSource = oDataSet
                End With
            Catch ex As Exception
                oConn = Nothing
                oCmd = Nothing
                oData = Nothing
                oDataSet = Nothing
                oAdapter = Nothing
            End Try
        End Sub
        Protected Sub OrgChart_NodeDataBound(sender As Object, e As Telerik.Web.UI.OrgChartNodeDataBoundEventArguments) Handles OrgChart.NodeDataBound
            ''e.Node.CssClass = "SmallNode"
            'If e.Node.Level = 1 Then
            '    e.Node.Collapsed = True
            'ElseIf e.Node.Level > 1 Then
            '    'e.Node.Collapsed = False
            'End If
            e.Node.CssClass = "Level" & e.Node.Level
            For Each oGroupItem As OrgChartGroupItem In e.Node.GroupItems
                If NameOnly.Checked Then
                    oGroupItem.CssClass = "SmallNodeNameOnly"
                    oGroupItem.CssClass = "SmallNode"
                End If
        End Sub
        Private Sub OrgChart_NodeExpandCollapse(sender As Object, e As OrgChartNodeExpandCollapseEventArguments) Handles OrgChart.NodeExpandCollapse
                If e.State = OrgChartNodeExpandCollapseState.NodeCollapsed Then
                    For Each employee As OrgChartNode In e.SourceNode.Nodes
                        employee.Collapsed = True
                End If
            Catch ex As Exception
            End Try
        End Sub
Back to Top