event BeforeExpandItem (Group as Group, Item as HITEM, ByRef 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 (By Reference) 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. 

Syntax for BeforeExpandItem event, /NET version, on:

private void BeforeExpandItem(object sender,exontrol.EXPLORERTREELib.Group Group,int Item,ref object Cancel)
{
}

Private Sub BeforeExpandItem(ByVal sender As System.Object,ByVal Group As exontrol.EXPLORERTREELib.Group,ByVal Item As Integer,ByRef Cancel As Object) Handles BeforeExpandItem
End Sub

Syntax for BeforeExpandItem event, /COM version, on:

private void BeforeExpandItem(object sender, AxEXPLORERTREELib._IExplorerTreeEvents_BeforeExpandItemEvent e)
{
}

void OnBeforeExpandItem(LPDISPATCH Group,long Item,VARIANT FAR* Cancel)
{
}

void __fastcall BeforeExpandItem(TObject *Sender,Explorertreelib_tlb::IGroup *Group,Explorertreelib_tlb::HITEM Item,Variant * Cancel)
{
}

procedure BeforeExpandItem(ASender: TObject; Group : IGroup;Item : HITEM;var Cancel : OleVariant);
begin
end;

procedure BeforeExpandItem(sender: System.Object; e: AxEXPLORERTREELib._IExplorerTreeEvents_BeforeExpandItemEvent);
begin
end;

begin event BeforeExpandItem(oleobject Group,long Item,any Cancel)
end event BeforeExpandItem

Private Sub BeforeExpandItem(ByVal sender As System.Object, ByVal e As AxEXPLORERTREELib._IExplorerTreeEvents_BeforeExpandItemEvent) Handles BeforeExpandItem
End Sub

Private Sub BeforeExpandItem(ByVal Group As EXPLORERTREELibCtl.IGroup,ByVal Item As EXPLORERTREELibCtl.HITEM,Cancel As Variant)
End Sub

Private Sub BeforeExpandItem(ByVal Group As Object,ByVal Item As Long,Cancel As Variant)
End Sub

LPARAMETERS Group,Item,Cancel

PROCEDURE OnBeforeExpandItem(oExplorerTree,Group,Item,Cancel)
RETURN

Syntax for BeforeExpandItem event, /COM version (others), on:

<SCRIPT EVENT="BeforeExpandItem(Group,Item,Cancel)" LANGUAGE="JScript">
</SCRIPT>

<SCRIPT LANGUAGE="VBScript">
Function BeforeExpandItem(Group,Item,Cancel)
End Function
</SCRIPT>

Procedure OnComBeforeExpandItem Variant llGroup HITEM llItem Variant llCancel
	Forward Send OnComBeforeExpandItem llGroup llItem llCancel
End_Procedure

METHOD OCX_BeforeExpandItem(Group,Item,Cancel) CLASS MainDialog
RETURN NIL

void onEvent_BeforeExpandItem(COM _Group,int _Item,COMVariant /*variant*/ _Cancel)
{
}

function BeforeExpandItem as v (Group as OLE::Exontrol.ExplorerTree.1::IGroup,Item as OLE::Exontrol.ExplorerTree.1::HITEM,Cancel as A)
end function

function nativeObject_BeforeExpandItem(Group,Item,Cancel)
return

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