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

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

0 Answers 97 Views
OrgChart
This is a migrated thread and some comments may be shown as answers.
Johnathan
Top achievements
Rank 1
Johnathan asked on 20 Feb 2018, 06:00 PM

Hello,

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
 
        Try
            oConn.Open()
 
            'get employee hierarchy
            With oCmd
                .Parameters.Clear()
                .Connection = oConn
                .CommandType = Data.CommandType.StoredProcedure
                .CommandText = "EmployeeHierachySP"
                .Parameters.AddWithValue("@NameOnly", NameOnly.Checked)
            End With
            oAdapter.Fill(oDataSet)
 
            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
 
                .DataBind()
            End With
 
        Catch ex As Exception
            Response.Write(ex.ToString)
        Finally
            oConn.Dispose()
            oConn = Nothing
            oCmd = Nothing
            oData = Nothing
            oDataSet.Dispose()
            oDataSet = Nothing
            oAdapter.Dispose()
            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"
            Else
                oGroupItem.CssClass = "SmallNode"
            End If
        Next
    End Sub
 
    Private Sub OrgChart_NodeExpandCollapse(sender As Object, e As OrgChartNodeExpandCollapseEventArguments) Handles OrgChart.NodeExpandCollapse
        Try
 
            If e.State = OrgChartNodeExpandCollapseState.NodeCollapsed Then
 
                For Each employee As OrgChartNode In e.SourceNode.Nodes
                    employee.Collapsed = True
                Next
            End If
        Catch ex As Exception
 
        End Try
    End Sub

No answers yet. Maybe you can help?

Tags
OrgChart
Asked by
Johnathan
Top achievements
Rank 1
Share this question
or