ComponentOne VSFlexGrid 8.0
BeforeCollapse Event

Fired before the user expands or collapses one or more rows in an outline.

Syntax

Private Sub VSFlexGrid_BeforeCollapse( ByVal Row As Long,  ByVal State As Integer, Cancel As Boolean)

Remarks

This event is fired when the grid is in outline mode, before a node is expanded or collapsed either through user action (clicking on the OutlineBar) or through code (setting the IsCollapsed property or invoking the Outline method).

The parameters for the BeforeCollapse event are described below:

Row As Long

If a single node is being expanded or collapsed, this parameter has the row number of the node being expanded or collapsed. If multiple nodes are being collapsed or expanded, this parameter is set to -1.

State As Integer

If a single node is being expanded or collapsed, this parameter has the new state of the node. If multiple node are being collapsed or expanded, this parameter is set to the new outline level being displayed. Possible node states are described below.

Cancel As Boolean

Set this parameter to True to prevent the node from being collapsed or expanded.

Possible node states are:

 

Constant

Value

Description

FlexOutlineExpanded

0

The node is expanded: all subordinate nodes are visible.

FlexOutlineSubtotals

1

The node is partially expanded: subordinates nodes are visible but collapsed.

FlexOutlineCollapsed

2

The node is collapsed: all subordinate nodes are hidden.

 

Single nodes are expanded or collapsed when the user clicks the outline tree (see the OutlineBar property) or when a new node state is assigned to the IsCollapsed property of a specific row. Multiple nodes are expanded or collapsed when the user clicks the outline buttons across the top of the outline tree or when the Outline method is invoked by the host application.

This event is especially useful for building outlines asynchronously. One of the samples provided on the distribution CD uses this technique to build a directory tree display. Branches are added to the tree when the user expands each directory. In this case, building the entire tree when the control loads would take too long.

The sample code below creates an outline with five nodes, each of which contains an empty "dummy" child node. Before a parent node is expanded, the dummy child is removed and five new parent nodes are added, each with a dummy child. Thus the outline tree is build dynamically and can grow indefinitely.

    Private Sub Form_Load()

        fg.Rows = 1

        fg.Cols = 1

        fg.FixedCols = 0

        fg.ExtendLastCol = True

        fg.OutlineBar = flexOutlineBarSimpleLeaf

        AddNodeGroup 1, 0

    End Sub

    Private Sub fg_BeforeCollapse(ByVal Row As Long, ByVal State As Integer, Cancel As Boolean)

        If Row < 0 Then Cancel = True: Exit Sub

        If State = flexOutlineCollapsed Then Exit Sub

        If fg.TextMatrix(Row + 1, 0) <> "Dummy" Then Exit Sub

        fg.RemoveItem Row + 1

        AddNodeGroup Row + 1, fg.RowOutlineLevel(Row) + 1

    End Sub

    Sub AddNodeGroup(r&, level&)

        Dim i%

        For i = 1 To 5

            fg.AddItem "Row " & fg.Rows, r

            fg.AddItem "Dummy", r + 1

            fg.IsSubtotal(r) = True

            fg.RowOutlineLevel(r) = level

            fg.IsCollapsed(r) = flexOutlineCollapsed

            r = r + 2

        Next

    End Sub

The control is initialized in the Form_Load event. The OutlineBar property is used to display an outline tree, and the AddNode routine is called to add a block of five nodes with dummy children.

Before a node is expanded or collapsed, the BeforeCollapse event is fired. If the Row parameter is negative, the operation is canceled (this happens when the user shift-clicks a node to expand or collapse all nodes at that level). If the node is being collapsed or the child node is not a dummy, the function exits without further processing. Otherwise, the dummy is removed and replaced with a new group of collapsed nodes.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback