event BeforeExpandItem (Group as Group, Item as HITEM, Cancel as Variant)
Fired before an item is about to be expanded (collapsed).

 TypeDescription 
   Group as Group A Group object where the user expands or collapse an item.  
   Item as HITEM A long expression that indicates the handle of the item being expanded or collapsed.  
   Cancel as Variant A boolean expression that indicates whether the control cancel expanding or collapsing the item.  
The BeforeExpandItem event notifies your application that an item is about to be collapsed or expanded. Use the BeforeExpandItem event to cancel expanding or collapsing items. The AfterExapandItem event is fired after an item is expanded or collapsed.  Use the ExpandItem method to programmatically expand or collapse an item. 

The following sample cancels expanding or collapsing items in the first group:

Private Sub ExplorerTree1_BeforeExpandItem(ByVal Group As EXPLORERTREELibCtl.IGroup, ByVal Item As EXPLORERTREELibCtl.HITEM, Cancel As Variant)
    If (Group.Index = 0) Then
        Cancel = True
    End If
End Sub

If your application expands items programmatically  and you need to disable expanding or collapsing items only when user tries to click the left button of each parent item you can use an internal counter like in the following sample:

Dim iExpanding As Long

iExpanding = 0

iExpanding = iExpanding + 1
....
do expanding/collapsing items
...
iExpanding = iExpanding - 1

Private Sub ExplorerTree1_BeforeExpandItem(ByVal Group As EXPLORERTREELibCtl.IGroup, ByVal Item As EXPLORERTREELibCtl.HITEM, Cancel As Variant)
    If iExpanding = 0 Then
        If (Group.Index = 0) Then
            Cancel = True
        End If
    End If
End Sub 

Send comments on this topic.
© 1999-2008 Exontrol Inc, Software. All rights reserved.